Ansible Command module says that '|' is illegal character Ansible Command module says that '|' is illegal character shell shell

Ansible Command module says that '|' is illegal character


From the doc:

command - Executes a command on a remote node

The command module takes the command name followed by a list ofspace-delimited arguments. The given command will be executed on allselected nodes. It will not be processed through the shell, sovariables like $HOME and operations like "<", ">", "|", and "&" willnot 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 commandthrough 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