0

Ansible wiki says: The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and operations like "<", ">", "|", ";" and "&" will not work (use the shell module if you need these features).

But there is no difference between them in Ansible:

[oracle@temp ansible]$ ansible temp2 -m shell -a "ls -la $HOME"
temp2 | CHANGED | rc=0 >>
total 40
drwx------. 6 oracle dba   4096 May 16 15:31 .
drwxr-xr-x. 3 root   root    20 Mar 18 18:45 ..
drwx------. 3 oracle dba     17 May 16 15:31 .ansible
-rw-------. 1 oracle dba   8100 Apr 17 12:50 .bash_history
-rw-r--r--. 1 oracle dba     18 Aug 24  2018 .bash_logout
-rw-r--r--. 1 oracle dba    257 Mar 19 10:53 .bash_profile
-rw-r--r--. 1 oracle dba    231 Aug 24  2018 .bashrc
drwx------. 3 oracle dba     16 Mar 22 12:19 .cache
drwx------. 4 oracle dba     28 Mar 22 12:19 .config
drwx------. 3 oracle dba     19 Mar 22 12:19 .local
-rw-------. 1 oracle dba  10425 Apr 16 14:50 .psql_history
-rw-------. 1 oracle dba    713 Mar 19 11:15 .viminfo

[oracle@temp ansible]$ ansible temp2 -m command -a "ls -la $HOME"
temp2 | CHANGED | rc=0 >>
total 40
drwx------. 6 oracle dba   4096 May 16 15:31 .
drwxr-xr-x. 3 root   root    20 Mar 18 18:45 ..
drwx------. 3 oracle dba     17 May 16 15:31 .ansible
-rw-------. 1 oracle dba   8100 Apr 17 12:50 .bash_history
-rw-r--r--. 1 oracle dba     18 Aug 24  2018 .bash_logout
-rw-r--r--. 1 oracle dba    257 Mar 19 10:53 .bash_profile
-rw-r--r--. 1 oracle dba    231 Aug 24  2018 .bashrc
drwx------. 3 oracle dba     16 Mar 22 12:19 .cache
drwx------. 4 oracle dba     28 Mar 22 12:19 .config
drwx------. 3 oracle dba     19 Mar 22 12:19 .local
-rw-------. 1 oracle dba  10425 Apr 16 14:50 .psql_history
-rw-------. 1 oracle dba    713 Mar 19 11:15 .viminfo

What is the reason?

6

You're passing the parameter in double quotes. $HOME is expanded by the shell on your local machine, ansible doesn't even get to see it. If you use single quotes instead, you should be able to see a difference. (You would also have noticed if the path didn't exist on the remote machine.)

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.