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