Ansible Ad-Hoc Commands & examples

Ad-Hoc commands are single liner commands which allow us to do something quickly but don’t want to save for later.

To list all hosts
ansible --list-hosts all

To list hosts in a group
ansible --list-hosts groupname

Negation – to list all hosts except one group
ansible --list-hosts \!groupname

To run a command as a specific user
ansible -m command -a "command you wish to run" groupname -u ubuntu

Post navigation

Alvin Jaison

Myself Alvin Jaison. I'm a DevOps Engineer by Profession; A Mountaineer by Passion. I started this website to share DevOps related posts. Post your suggestions as a comment. You can reach me @

One thought on “Ansible Ad-Hoc Commands & examples

Leave a Reply

Your email address will not be published. Required fields are marked *