Sunday, December 1, 2019

Ansible Cheat Sheet

REFERENCE

Playbooks

ansible-playbook                    # Run on all hosts defined
ansible-playbook  -f 10             # Run 10 hosts parallel
ansible-playbook  --verbose         # Verbose on successful tasks
ansible-playbook  -C                # Test run
ansible-playbook  -C -D             # Dry run
ansible-playbook  -l          # Run on single host
Run Infos
ansible-playbook  --list-hosts
ansible-playbook  --list-tasks
Syntax Check
ansible-playbook --syntax-check 

Remote Execution

ansible all -m ping
Execute arbitrary commands
ansible  -a 
ansible all -a "ifconfig -a"

Debugging

List facts and state of a host
ansible  -m setup                            # All facts for one host
ansible  -m setup -a 'filter=ansible_eth*'   # Only ansible fact for one host
ansible all -m setup -a 'filter=facter_*'          # Only facter facts but for all hosts
Save facts to per-host files in /tmp/facts
ansible all -m setup --tree /tmp/facts