Is it possible to use bracket expansion in an ad-hoc command? I'm trying to do:

ansible web3 -m shell -a "sudo gzip /var/opt/tomcat/logs/appname.log.2015-05-2{4..7}" -K

But it's being interpreted as a string. Is this a situation where I might need to use xargs?


Is the host web3 a recent Debian/Ubuntu server where /bin/sh is actually dash? The bracket expansion is not supported by it. You might need to specify executable option to shell module.

$ ansible -i localhost, all -m shell -a 'ls /var/log/syslog.{2..4}.gz'
localhost | FAILED | rc=2 >>
ls: cannot access /var/log/syslog.{2..4}.gz: No such file or directory

$ ansible -i localhost, all -m shell -a 'ls /var/log/syslog.{2..4}.gz executable=/bin/bash'
localhost | success | rc=0 >>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.