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

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

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.

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