I'm getting an unexpected behavior from executing a shell remotely with Ansible. When I execute the following command on the remote machine, the result is:
$ echo $(pgrep -f jboss)
13248
Now if I execute the command as Ansible shell I get as return multiple pids:
$ ansible jboss.servers -m shell -a 'echo $(pgrep -f jboss)' -u centos
10.3.9.155 | SUCCESS | rc=0 >>
13248 16362 16363
As I need to further elaborate the shell, I need to find a way to get the same result as if I'm on the remote machine. I've tried with:
'echo $(pgrep -f jboss | awk '{ print $1 }')'
But that doesn't work because the expression is already in single quotes. Any help ?