cannot stat command with * and `

2,360 views
Skip to first unread message

Naoko Reeves

unread,
Feb 9, 2014, 1:06:49 AM2/9/14
to ansible...@googlegroups.com
I am trying to rename folder that is unpacked. So I can only get file name accurately with grep (or some sort of regex expression)

via ansible, the following command fails with the error message: stderr: mv: cannot stat `/var/www/`ls /var/www/ | grep client`': No such file or directory

command mv "/var/www/`ls /var/www/ | grep client`" "/var/www/gd_new"

however, exact command works just fine when executed on server

I try to use mv "var/www/client*" "/var/www/gd_new", with xargs with pipe... all end up with similar error...

any guidance would be appreciated. 


Brian Coca

unread,
Feb 9, 2014, 8:14:07 AM2/9/14
to ansible...@googlegroups.com
can you show the play/tasks involved?

Naoko Reeves

unread,
Feb 9, 2014, 8:55:11 AM2/9/14
to ansible...@googlegroups.com
yes this is the task. only "mv" fails...

- name: example_client | download archived dist, unpack and cleanup
  command: "{{item}}"
  with_items:
    - curl -H "Authorization:token {{ git_token }}" -L -o /var/www/example.zip "https://api.github.com/repos/user/example_client/zipball/gh-pages"
    - unzip /var/www/example.zip -d /var/www
    - mv "/var/www/`ls /var/www/ | grep client`" "/var/www/example_new"
  tags: 
    - deploy

Dag Wieers

unread,
Feb 9, 2014, 10:06:28 AM2/9/14
to ansible...@googlegroups.com
Substitute "command" by "shell". The shell module allows to do piping,
backticks, globs, etc.. The command module does not do any of those things
and can only be used for a single static command line.

--
-- dag wieers, d...@wieers.com, http://dag.wieers.com/
-- dagit linux solutions, con...@dagit.net, http://dagit.net/

[Any errors in spelling, tact or fact are transmission errors]

Michael DeHaan

unread,
Feb 9, 2014, 4:22:51 PM2/9/14
to ansible...@googlegroups.com
Yes, you need to use the shell module.  However, much of this can be refactored.

curl should probably use the "get_url" module, etc.

There's also the "unarchive" module, so you could do a local play to download the contents to the Ansible control machine and follow that up with unarchive to avoid the download happening on every host.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Naoko Reeves

unread,
Feb 9, 2014, 4:39:46 PM2/9/14
to ansible...@googlegroups.com
Dag, Michael,
Thank you, that solved the issue.
Reply all
Reply to author
Forward
0 new messages