# command using pipes does not work when using ansible without a playbook

**URL:** <https://forum.ansible.com/t/command-using-pipes-does-not-work-when-using-ansible-without-a-playbook/27128>\
**Category:** Ansible Project\
**Created:** [March 27, 2018, 1:50pm UTC](https://forum.ansible.com/t/command-using-pipes-does-not-work-when-using-ansible-without-a-playbook/27128 "2018-03-27T13:50:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abey\_Thomas](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Abey\_Thomas](https://forum.ansible.com/u/Abey_Thomas)\
**Post date:** [March 27, 2018, 1:50pm UTC](https://forum.ansible.com/t/command-using-pipes-does-not-work-when-using-ansible-without-a-playbook/27128/1 "2018-03-27T13:50:48Z")

</div>

Hi,

I would like to use ansible to execute commands on a host.

This works

`  
ansible -i ./ec2.py 192.168.108.53 -s -u ansible -a “rpm -qa --last kernel”

`

This does not work as expected the output of rpm is given as the final output. I would like to filter the output further.

`  
ansible -i ./ec2.py 192.168.108.53 -s -u ansible -a “rpm -qa --last | grep kernel”

`

Any suggestions?

Regards,  
Abey

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 27, 2018, 1:54pm UTC](https://forum.ansible.com/t/command-using-pipes-does-not-work-when-using-ansible-without-a-playbook/27128/2 "2018-03-27T13:54:06Z")

</div>

command module doesn't support pipe and redirect, only shell and raw do that.

Ansible ad-hoc uses command module as default, so you need add "-m shell" to make pipes work.

---

<div class="post-metadata">

**Author:** ![Abey\_Thomas](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@Abey\_Thomas](https://forum.ansible.com/u/Abey_Thomas)\
**Post date:** [March 27, 2018, 2:42pm UTC](https://forum.ansible.com/t/command-using-pipes-does-not-work-when-using-ansible-without-a-playbook/27128/3 "2018-03-27T14:42:55Z")

</div>

Hi Kai,

Did not know that I had use shell. Thanks . Works OK.

`  
ansible -i ./ec2.py 192.168.108.53 -m shell -s -u ansible -a “rpm -qa --last | grep kernel”

`

Regards,  
Abey
