I've run into this too. My workaround is to use the script module instead of the shell module. Then you don't have to fight with Ansible about quotes.
Added benefit: you can put your script under Version Control. ansible host1 -m script -a example.sh On Apr 20, 2016 12:21 PM, "Chris D" <[email protected]> wrote: > I'm trying to run a command using the Ansible shell module, but having > some trouble. Basically, with this command, I want to list all postgres > databases on a server, then run the psql -c '\dx' command against them to > find out what extensions are installed in each database in the cluster. > > Unfortunately, I haven't been able to find the right combination of > quotes/single quotes to get the command to run successfully. > > Example: host1 has 3 postgres databases on it: db1, db2, and db3 > > ansible 'host1' -m shell -a 'for database in $(psql -l | grep '^ db' | awk > '{print $1}'); do psql -c '\dx'; done > > I've tried enclosing the whole 'for... done' command in double-quotes, > etc, but no luck :( > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/97962ea8-9fd7-49c0-b3f8-c230c4e1670a%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/97962ea8-9fd7-49c0-b3f8-c230c4e1670a%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CANNWuVVN%2B0S1g69t%3DXtr%2BKQW2pOP9jB0U8CV1e0FZ4r55%2BJeTQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
