Ansible Command module says that ‘|’ is illegal character
The ansible.builtin.command
module in Ansible has some restrictions, and one of them is that it does not support shell-specific operations like pipes (|
), redirects (>
, >>
), or using environment variables. This is because the command
module executes commands directly, without invoking a shell. To use shell features like the pipe operator (|
), you need to use the ansible.builtin.shell
module instead.
Solutions
1. Use the ansible.builtin.shell
Module
Switch from using the command
module to the shell
module if you need to use pipes or other shell features.
Example.
- name: Using shell module with pipe
ansible.builtin.shell: "cat /etc/passwd | grep root"
2. Use the ansible.builtin.command
Module without Shell Features
If you do not need shell features, you should structure your command without pipes or other shell-specific syntax.
Example.
- name: Using command module without shell features
ansible.builtin.command:
cmd: "cat /etc/passwd"
- Use
ansible.builtin.shell
if you need to use shell features like pipes. - Use
ansible.builtin.command
for simple commands without shell features.
Using the appropriate module based on your needs will avoid errors like '|' is an illegal character
.
Swaraa Tech Solutions offers top-notch Web Design Services and Web Development in Ahmedabad. Our App Development Company is known for delivering innovative solutions. We also specialize in SEO Services Ahmedabad and Social Media Marketing to boost your online presence. Experience the best with our AWS Cloud Solutions. Contact us today for a free consultation!
Follow for more!
Visit our website: www.swaraa.dev
Mail us at: info@swaraa.dev
Call us on 07935336883