How to debug shell commands

I tried a command with the shell and it just hung:

ansible -D -i server.lst cloud1.hens-teeth.net -m shell -a ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

No output at all. More on that in a bit.

It works fine with ssh:

ssh cloud1.hens-teeth.net ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

Which led me to wondering about how to debug something like this. I had hoped that -D would give me something to work with but I got nada. Short of diving into the Python code and adding print statements, do you have suggestions?

Returning to the command that I wanted to run, I think that it is waiting for a password to be entered. It I put some backslashed in front of the dollar sign, I get different output. I haven’t found a quantity of backslashed that work. How many do you think I should have?

Thanks,
– Art Z.

I tried a command with the shell and it just hung:

ansible -D -i server.lst cloud1.hens-teeth.net -m shell -a ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

No output at all. More on that in a bit.

It works fine with ssh:

ssh cloud1.hens-teeth.net ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

Which led me to wondering about how to debug something like this. I had hoped that -D would give me something to work with but I got nada. Short of diving into the Python code and adding print statements, do you have suggestions?

-D provides module debug output only.

Returning to the command that I wanted to run, I think that it is waiting for a password to be entered. It I put some backslashed in front of the dollar sign, I get different output. I haven’t found a quantity of backslashed that work. How many do you think I should have?

Ansible shouldn’t ask for a password unless you use --ask-pass. Note that ansible is trying root unless you pass in “-u” to ansible.

This should of course immediately die, not hang.

Sudo may hang if you were using --sudo, at least in 0.3 implementations.

Michael,

ansible wasn’t waiting for a password. I think that mysqlcheck was waiting for a password. I think that

$(cat /etc/psa/.psa.shadow)

evaluated to an empty string, which would make mysqlcheck prompt for a password.

Is there a way to get

/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases

to run properly in the shell module? I enclosed the whole thing in single quotes and tried 0, 1, 2, 4, 6 and 8 backslashes in front of the dollar sign. None worked.

With ssh, it’s easy. Just type:

ssh cloud1.hens-teeth.net ‘/usr/bin/mysqlcheck -uadmin -p$(cat /etc/psa/.psa.shadow) --all-databases’

No backslashes needed at all.

– Art Z.

your local shell MAY be eating things. Try escaping the $?

in lieu of $(stuff)

try:

`stuff`

I've found backticks are easier to swallow by the shell.

-sv

Oh, you WANT the shell to evaluate that locally. Interesting.

Seth: I’ll try backticks and see if it works better.

Michael: No, I want the command executed remotely, not locally.

BTW, I do understand that I am moving afield from “configuration management” into “system management” and that this is not what ansible is intended to do. I was just playing with using ansible in lieu of pssh and hit this curiosity.

– Art Z.