Skip to content

as bruce

$ ansible all -m ping -u bruce

as bruce, sudoing to root

$ ansible all -m ping -u bruce --sudo

as bruce, sudoing to batman

$ ansible all -m ping -u bruce --sudo --sudo-user batman

With latest version of ansible sudo is deprecated so use become

as bruce, sudoing to root

$ ansible all -m ping -u bruce -b

as bruce, sudoing to batman

$ ansible all -m ping -u bruce -b --become-user batman

run a live command on all of your nodes:

$ ansible all -a "/bin/echo hello"

You can specify localhost explicitly by adding this to your inventory file: localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python"

To list all the facts about a system

ansible localhost -m setup

https://medium.com/@dhoeric/ansible-dynamic-inventory-with-aws-ec2-80d075fcf430

taget instances using ec2 tags:

tags EC2, such as App=backend Environment=staging Usage=clock-worker

Download ec2.py and ec2.ini, put the files on ./inventory from your playbook directory.

Run in ansible / ansible-playbook

ansible -i ./inventory/ec2.py --limit "tag_App_backend:&tag_Environment_staging:&tag_Usage_clock_worker" -m ping all
ansible-playbook -i ./inventory/ec2.py --limit "tag_App_backend:&tag_Environment_staging:&tag_Usage_clock_worker" deploy.yml

or

  • hosts:
    • tag_class_vpn_dev:&tag_environment_london