Skip to content

Instantly share code, notes, and snippets.

@aleixripoll
Last active April 1, 2017 10:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aleixripoll/a9465ebde18eee4ac7bc82131b1e9818 to your computer and use it in GitHub Desktop.
Save aleixripoll/a9465ebde18eee4ac7bc82131b1e9818 to your computer and use it in GitHub Desktop.
Ansible tips

Playbook useful switches:

ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml

-C check_mode
-D show file diffs

Ad-hoc commands:

ansible -i <inventory> <host/hostgroup> -a <command>
EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"

Gather facts from a host:

ansible -m setup -i <inventory> <host>

Search for pattern in all encrypted vault files:

for f in $(grep -rl '$ANSIBLE_VAULT;1.1'); do echo $f:; ansible-vault view $f | grep <pattern>; done

Intersect conditions in host limit option

ansible-playbook -i inventory/ec2.py meta.yml --list-hosts -l "tag_Name_a:&tag_Role_b:&tag_Environment_c"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment