# fallback: install required python2 over SSH on remote machine
ansible example.com -i inventory -u root -m raw -a "apt-get update && apt-get install -y python-minimal"
# Ad-hoc commands
ansible all -i inventory.list -l localhost -u root -m ping
ansible all -s -m shell -a "hostname -f"
ansible all -s -m apt -a 'pkg=nginx state=installed update_cache=true'
# uptime
ansible all -i inventories/dev -l www -u root -a uptime
ansible all -m shell -a "apt-get update"
ansible www.example.com -m setup
ansible all -m setup -i inventory/example.com -u root > /tmp/example.com.inventory.$(date -I).txt
ansible www.example.com -m setup -a "filter=ansible_ssh_host_key_rsa_public"
ansible www.example.com -i inventories/prod -m setup -a "filter=*host_key*"
ansible all -m setup -a "filter=ansible_processor_vcpus"
ansible all -m setup -a "filter=ansible_all_ipv4_addresses"
ansible localhost -m setup
ansible all -i inventories/prod -l '!localhost,!nas,!proxy' -m setup -a "filter=ansible_memtotal_mb"
# set temporary host ip
ansible-playbook example.yml -i inventories/dev -e ansible_host=192.168.1.11
ansible-playbook example.yml -e ansible_ssh_user=root -e "ansible_ssh_common_args='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'"
ansible localhost -m setup -a "filter=ansible_date_time"
# Generate JSON Inventory
ansible all -m setup -i inventories/prod --tree /tmp/facts
for i in $(ls -1 /tmp/facts/*); do cat $i | python -m json.tool > $i.json; done
# reboot all hosts in group
ansible -i inventory www -m shell -a nohup reboot
# syntax check
ansible-playbook foo.yml --syntax-check
# define python interpreter
ansible localhost -m ping -e 'ansible_python_interpreter=/usr/bin/python3'