Skip to content

Instantly share code, notes, and snippets.

@swdream
Last active August 26, 2018 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swdream/fba5dc53cc94075076b3107936897a40 to your computer and use it in GitHub Desktop.
Save swdream/fba5dc53cc94075076b3107936897a40 to your computer and use it in GitHub Desktop.
  1. ping all hosts:
ansible all -m ping
  1. using user
ansible all -m ping -u bruce
  1. Using sudo
ansible all -m ping -u bruce --sudo 
ansible all -m ping -u bruce --sudo --sudo-user batman

# as bruce, sudoing to batman
$ ansible all -m ping -u bruce -b --become-user batman
  1. Run commands
$ ansible all -a "/bin/echo hello"
$ ansible remote_host -a "commands"
  1. file transfer
$ ansible atlanta -m copy -a "src=/etc/hosts dest=/tmp/hosts"
  1. Managing packages
$ ansible webservers -m yum -a "name=acme state=present"
  1. Managing services
$ ansible webservers -m service -a "name=httpd state=started"
  1. check syntax of playbook using --syntax-check

  2. list all host affected

ansible-playbook playbook.yml --list-hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment