cannot stat command with * and `

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.

can you show the play/tasks involved?

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

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.

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.

Dag, Michael,
Thank you, that solved the issue.