Ansible Command Module Says That '|' Is Illegal Character


Answer :

From the doc:

command - Executes a command on a remote node

The command module takes the command name followed by a list of space-delimited arguments. 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).

shell - Executes a commands in nodes

The shell module takes the command name followed by a list of space-delimited arguments. It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node.

Therefore you have to use shell: dpkg -l | grep python-apt.


read about the command module in the Ansible documentation:

It will not be processed through the shell, so .. operations like "<", ">", "|", and "&" will not work

As it recommends, use the shell module:

- name: Check if python-apt is installed   shell: dpkg -l | grep python-apt   register: python_apt_installed   ignore_errors: True 

For what it's worth, you can check/confirm the installation in a debian environment using the apt command:

- name: ensure python-apt is installed   apt: name=python-apt state=present 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?