Ansible Command module says that ‘|’ is illegal character

Question:

I am using Ansible to deploy my project and I trying to check if an specified package is installed, but I have a problem with it task, here is the task:

And here is the problem:

Why is illegal this 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.

Leave a Reply