Ansible Ad-Hoc Commands – 1

# ansible all -i hosts --list-hosts		(To see all hosts in inventory file named hosts)

# ansible rl6 -i hosts --list-hosts		(To see hosts of host group named rl6 created in inventory)

# ansible ungrouped -i hosts --list-hosts	(To see ungrouped hosts)

# ansible rhel -i hosts --list-hosts		(To see group parent to contains children where rhel is parent name)

# ansible all -m command -a "uptime"		(An ad-hoc command example to check uptime of hosts)

# ansible all -m command -a "uptime" -k -K	(An ad-hoc command example to check uptime of hosts which will ask for SSh password and sudo)

# ansible-doc ping				(Command to see help page for ping module)

# ansible rl6 -m shell -a "lscpu | head -n 5"	(Command to check lscpu, -m command will not work as "command module not supprt pipe & redirection")

# ansible rl6 -m raw -a "cat /etc/redhat-release"	(raw module just uses SSH and bypasses the Ansible module subsystem.)

# ansible all -m command -a 'ls -l /tmp/first.txt'	(Command will check file exists or not)

# ansible-playbook --syntax-check playbooks/create-file.yml		(Command to check playbook syntax)

# ansible-playbook playbooks/create-file.yml	(Command to run a playbook named create-file.yml)

# ansible-playbook --check playbooks/archive-message.yml	(It will do a dry run of your playbook)

# ansible-playbook --list-hosts playbooks/archive-message.yml	(You can list your hosts on which playbook will run)

# ansible-playbook --list-tasks playbooks/archive-message.yml	(You can list your tasks available in playbook)

Leave a Reply

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