Run an ad-hoc shell command

Run a shell command on all webservers with sudo (-b)

ansible webservers -i inventory.ini -m shell -a 'df -h' -b

tool
ansible56 commands
tags
ansible

More ansible commands

  • ansible myhost -i inventory.ini -m setup | jq '.ansible_facts.ansible_distribution'

    Collect Ansible facts for one host and show the OS name

  • ansible-playbook site.yml -i inventory.ini --tags 'nginx,ssl'

    Run only the tasks tagged nginx or ssl

  • ansible-playbook site.yml -i inventory.ini --skip-tags 'slow,optional'

    Skip tasks tagged slow or optional

  • ansible-vault encrypt_string 'mysecretpassword' --name 'db_password'

    Encrypt one string so you can paste it straight into vars

  • ansible-playbook deploy.yml -i inventory.ini --limit 'web01,web02'

    Run the playbook only on web01 and web02

all 56 ansible commands