Skip to content

Instantly share code, notes, and snippets.

@mbodo
Forked from aleixripoll/ansible-tips.md
Last active March 11, 2019 15:35
Show Gist options
  • Save mbodo/b107bdfd3160c9cfc76db5c33d6f53b2 to your computer and use it in GitHub Desktop.
Save mbodo/b107bdfd3160c9cfc76db5c33d6f53b2 to your computer and use it in GitHub Desktop.

Revisions

  1. mbodo revised this gist Mar 11, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -129,4 +129,5 @@ Official:
    Others:
    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
    * [ansible-best-practises] (https://github.com/enginyoyen/ansible-best-practises)
    * [ansible-local-playbooks] (https://www.tricksofthetrades.net/2017/10/02/ansible-local-playbooks/)
    * [ansible-local-playbooks] (https://www.tricksofthetrades.net/2017/10/02/ansible-local-playbooks/)
    * [ansible-vault-digitalocean] (https://www.digitalocean.com/community/tutorials/how-to-use-vault-to-protect-sensitive-ansible-data-on-ubuntu-16-04)
  2. mbodo revised this gist Nov 2, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -128,4 +128,5 @@ Official:

    Others:
    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
    * [ansible-best-practises] (https://github.com/enginyoyen/ansible-best-practises)
    * [ansible-best-practises] (https://github.com/enginyoyen/ansible-best-practises)
    * [ansible-local-playbooks] (https://www.tricksofthetrades.net/2017/10/02/ansible-local-playbooks/)
  3. mbodo revised this gist Apr 3, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -127,4 +127,5 @@ Official:
    * [Ansible - Module] All (http://docs.ansible.com/ansible/list_of_all_modules.html)

    Others:
    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
    * [ansible-best-practises] (https://github.com/enginyoyen/ansible-best-practises)
  4. mbodo revised this gist Apr 3, 2017. 1 changed file with 22 additions and 1 deletion.
    23 changes: 22 additions & 1 deletion Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ e.g
    ansible-playbook --list-tasks test.yml
    ```

    Outpt:
    Output:
    ```
    playbook: test.yml
    @@ -40,6 +40,27 @@ playbook: test.yml
    debug TAGS: [subset3]
    ```

    #### List hosts for playbook:
    ```
    ansible-playbook -i <inventory> --list-hosts <playbook>.yml
    e.g
    ansible-playbook -i ../development.ini --list-hosts nginx.yml
    ```

    Output:
    ```
    playbook: oracle.yml
    play #1 (oracle): Install and configure nginx server TAGS: []
    pattern: [u'oracle']
    hosts (2):
    vm2
    vm1
    ```


    ### ansible

    #### Ad-hoc commands:
  5. mbodo revised this gist Apr 1, 2017. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -20,6 +20,26 @@ ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hos
    #### 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"```

    #### List task for playbook:
    ```
    ansible-playbook --list-tasks <role>.yml
    e.g
    ansible-playbook --list-tasks test.yml
    ```

    Outpt:
    ```
    playbook: test.yml
    play #1 (default): Test playbook TAGS: []
    tasks:
    debug TAGS: [subset]
    testrole1/subset2 : Subset2 role task1 TAGS: [subset2]
    testrole1/subset2 : Subset2 role task2 TAGS: [subset2]
    debug TAGS: [subset3]
    ```

    ### ansible

    #### Ad-hoc commands:
  6. mbodo revised this gist Apr 1, 2017. 1 changed file with 22 additions and 6 deletions.
    28 changes: 22 additions & 6 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,14 @@
    ## Ansible - Cheatsheet

    ### ansible-galaxy

    #### Playbook template init with ansible-galaxy
    ```
    ansible-galaxy init roles/myrole
    ```

    ### ansible-playbook

    #### Playbook useful switches:
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    @@ -13,18 +17,31 @@ ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hos
    -D show file diffs
    ```

    #### 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"```

    ### ansible

    #### Ad-hoc commands:
    ```
    ansible -i <inventory> <host/hostgroup> -a <command>
    EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    e.g
    ansible -i development.ini vm1 -a "date"
    ```

    Output:
    ```
    192.XXX.XXX.XXX | SUCCESS | rc=0 >>
    Sat Apr X XX:46:06 BST 20XX
    ```

    #### Gather facts from a host:
    ```
    ansible -m setup -i <inventory> <host>
    ansible -i <inventory> <host> -m setup
    e.g
    ansible -m setup -i development.ini vm1
    ansible -i development.ini vm1 -m setup
    ```

    Output:
    @@ -56,12 +73,11 @@ Output:
    }
    ```

    ### other

    #### 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"```

    Reference links:

    Official:
  7. mbodo revised this gist Apr 1, 2017. 1 changed file with 32 additions and 2 deletions.
    34 changes: 32 additions & 2 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -20,11 +20,41 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    ```

    #### Gather facts from a host:
    ```ansible -m setup -i <inventory> <host>```
    ```
    ansible -m setup -i <inventory> <host>
    e.g
    ansible -m setup -i development.ini vm1
    ```

    Output:
    ```
    "ansible_selinux": {
    "config_mode": "enforcing",
    "mode": "enforcing",
    "policyvers": 28,
    "status": "enabled",
    "type": "targeted"
    },
    "ansible_service_mgr": "systemd",
    ...
    ```

    #### Ping host:
    ```ansible -m setup -i <inventory> <host>```
    ```
    ansible -m ping -i <inventory> <host>
    e.g
    ansible -m ping -i development.ini vm1
    ```

    Output:
    ```
    192.XXX.XXX.XXX | SUCCESS => {
    "changed": false,
    "ping": "pong"
    }
    ```

    #### 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```
  8. mbodo revised this gist Apr 1, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,9 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    ```ansible -m setup -i <inventory> <host>```


    #### Ping 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```

  9. mbodo revised this gist Apr 1, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ Reference links:
    Official:
    * [Ansible - Docs] (http://docs.ansible.com/ansible/index.html)
    * [Ansible - Module] Index (http://docs.ansible.com/ansible/modules_by_category.html)
    * [Ansible - Module] All (http://docs.ansible.com/ansible/list_of_all_modules.html)

    Others:
    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
  10. mbodo revised this gist Apr 1, 2017. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,8 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    Reference links:

    Official:
    * Ansible - Docs (http://docs.ansible.com/ansible/index.html)
    * Ansible - Module Index (http://docs.ansible.com/ansible/modules_by_category.html)
    * [Ansible - Docs] (http://docs.ansible.com/ansible/index.html)
    * [Ansible - Module] Index (http://docs.ansible.com/ansible/modules_by_category.html)

    Others:
    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
  11. mbodo revised this gist Apr 1, 2017. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -27,4 +27,12 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    ```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"```
    ```ansible-playbook -i inventory/ec2.py meta.yml --list-hosts -l "tag_Name_a:&tag_Role_b:&tag_Environment_c"```

    Reference links:

    Official:
    * Ansible - Docs (http://docs.ansible.com/ansible/index.html)
    * Ansible - Module Index (http://docs.ansible.com/ansible/modules_by_category.html)

    * [ansible-files-layout] (https://leucos.github.io/ansible-files-layout)
  12. mbodo revised this gist Apr 1, 2017. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,10 @@
    ## Ansible - Cheatsheet

    #### Playbook template init with ansible-galaxy
    ```
    ansible-galaxy init roles/myrole
    ```

    #### Playbook useful switches:
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
  13. mbodo renamed this gist Apr 1, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ansible-cheatsheet.md → Ansible - Cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    ## Ansible - Cheatsheet

    #### Playbook useful switches:
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
  14. mbodo renamed this gist Apr 1, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  15. @aleixripoll aleixripoll revised this gist Feb 23, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,7 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"


    #### 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```
    ```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"```
  16. @aleixripoll aleixripoll revised this gist Feb 23, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -15,5 +15,6 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    #### Gather facts from a host:
    ```ansible -m setup -i <inventory> <host>```

    #### Search pattern in encrypted vault file

    #### 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```
  17. @aleixripoll aleixripoll revised this gist Feb 23, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -14,3 +14,6 @@ EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"

    #### Gather facts from a host:
    ```ansible -m setup -i <inventory> <host>```

    #### Search pattern in encrypted vault file
    ```for f in $(grep -rl '$ANSIBLE_VAULT;1.1'); do echo $f:; ansible-vault view $f | grep <pattern>; done```
  18. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #### ansible-playbook useful switches:
    #### Playbook useful switches:
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
  19. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #### ansible-playbook useful switches:
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    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
  20. @aleixripoll aleixripoll revised this gist Feb 6, 2017. No changes.
  21. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    #### ansible-playbook useful switches
    #### ansible-playbook useful switches:
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    -C check_mode
    -D show file diffs
    ```

    #### Ad-hoc commands
    #### 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
    #### Gather facts from a host:
    ```ansible -m setup -i <inventory> <host>```
  22. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ### ansible-playbook useful switches
    #### ansible-playbook useful switches
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    @@ -12,5 +12,5 @@ ansible -i <inventory> <host/hostgroup> -a <command>
    EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    ```

    ### Gather facts from a host
    #### Gather facts from a host
    ```ansible -m setup -i <inventory> <host>```
  23. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    ### > ansible-playbook useful switches
    ### ansible-playbook useful switches
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    -C check_mode
    -D show file diffs
    ```

    ### > ad-hoc commands
    #### 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
    ### Gather facts from a host
    ```ansible -m setup -i <inventory> <host>```
  24. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    ### ansible-playbook useful switches
    ### > ansible-playbook useful switches
    ```
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    -C check_mode
    -D show file diffs
    ```

    ### ad-hoc commands
    ### > 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>
    ### > gather facts from a host
    ```ansible -m setup -i <inventory> <host>```
  25. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,7 @@ ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,
    ```
    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>
  26. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ### ansible-playbook useful switches
    ```
    ansible-playbook -C -D -i <inventory> -u <ssh-user> -e <var=value> -t tag1,tag2 --list-hosts -l host1,host2 play.yml
    ansible-playbook -C -D -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    -C check_mode
    -D show file diffs
  27. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 2 additions and 8 deletions.
    10 changes: 2 additions & 8 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,9 @@
    ### ansible-playbook useful switches
    ```
    ansible-playbook
    -i <inventory>
    -u <ssh-user>
    -e <var1=value>,<var2=value>
    -t tag1,tag2
    --list-hosts
    -l host1,host2
    ansible-playbook -C -D -i <inventory> -u <ssh-user> -e <var=value> -t tag1,tag2 --list-hosts -l host1,host2 play.yml
    -C check_mode
    -D show file diffs
    play.yml
    ```

    ### ad-hoc commands
  28. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,15 @@
    ### ansible-playbook useful switches
    ```
    ansible-playbook [-C] [-D] -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    ansible-playbook
    -i <inventory>
    -u <ssh-user>
    -e <var1=value>,<var2=value>
    -t tag1,tag2
    --list-hosts
    -l host1,host2
    -C check_mode
    -D show file diffs
    play.yml
    ```

    ### ad-hoc commands
  29. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 1 addition and 5 deletions.
    6 changes: 1 addition & 5 deletions ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,5 @@ ansible-playbook [-C] [-D] -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t t
    ### ad-hoc commands
    ```
    ansible -i <inventory> <host/hostgroup> -a <command>
    ```

    **Example.** Print date for instances in group api_socket and env beta:
    ```
    ansible -i inventory/beta tag_Role_api_socket -a "date"
    EXAMPLE: ansible -i inventory/beta tag_Role_api_socket -a "date"
    ```
  30. @aleixripoll aleixripoll revised this gist Feb 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ansible-tips.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ### ansible-playbook useful switches
    ```
    ansible-playbook [-C] [-D] -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag] [--list-hosts] [-l <hosts>] play.yml
    ansible-playbook [-C] [-D] -i <inventory> [-u <ssh-user>] [-e <var=value>] [-t tag1,tag2] [--list-hosts] [-l host1,host2] play.yml
    -C check_mode
    -D show file diffs