Skip to content

Instantly share code, notes, and snippets.

@zeitounator
Last active December 25, 2020 08:40
Show Gist options
  • Save zeitounator/066c5a64fad630d8e2ed3d155b731e6b to your computer and use it in GitHub Desktop.
Save zeitounator/066c5a64fad630d8e2ed3d155b731e6b to your computer and use it in GitHub Desktop.
[test_group]
localhost test_var=88
# This is the group definition used for the second run (remove previous)
# [test_group]
# localhost
[test_group:vars]
test_var=99
---
- name: Debug value of test_var
debug:
var: test_var
---
- hosts: test_group
gather_facts: false
roles:
- role: test_role
$ # Please note that gists do not accept subdirs in file names, so I replaced / with - above for the paths.
$ # I also prepended each file with a number that is not part of the path to keep a coherent order
$ # Commands below are using the resulting file tree and are run from the playbook root.
$ # Run playbook with initial inventory
$ ansible-playbook -i inventories/test_inventory/hosts.ini playbook.yml
PLAY [test_group] **********************************************************************************************************************************************************************************************************************
TASK [test_role : Debug value of test_var] *********************************************************************************************************************************************************************************************
ok: [localhost] => {
"test_var": 88
}
PLAY RECAP *****************************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
$ # Now edit the inventory file and change for the group def that is commented out in my example
$ ansible-playbook -i inventories/test_inventory/hosts.ini playbook.yml
PLAY [test_group] **********************************************************************************************************************************************************************************************************************
TASK [test_role : Debug value of test_var] *********************************************************************************************************************************************************************************************
ok: [localhost] => {
"test_var": 99
}
PLAY RECAP *****************************************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment