Last active
May 1, 2021 15:45
-
-
Save halberom/ef3ea6d6764e929923b0888740e05211 to your computer and use it in GitHub Desktop.
ansible - example of using include_vars to put vars under a specific key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# play.yml | |
--- | |
- hosts: localhost | |
connection: local | |
gather_facts: False | |
roles: | |
- test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# roles/test/tasks/main.yml | |
--- | |
- include_vars: | |
file: subdir/bar | |
name: foo | |
- debug: | |
var: foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# roles/test/vars/subdir/bar | |
--- | |
mysuperduperdict: | |
key1: | |
- abc | |
- def |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PLAY [localhost] *************************************************************************************************************************************************************************************************************************************************************** | |
TASK [test : include_vars] ***************************************************************************************************************************************************************************************************************************************************** | |
ok: [localhost] | |
TASK [test : debug] ************************************************************************************************************************************************************************************************************************************************************ | |
ok: [localhost] => { | |
"changed": false, | |
"foo": { | |
"mysuperduperdict": { | |
"key1": [ | |
"abc", | |
"def" | |
] | |
} | |
} | |
} | |
PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************* | |
localhost : ok=2 changed=0 unreachable=0 failed=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible-playbook --version | |
ansible-playbook 2.3.0.0 | |
config file = | |
configured module search path = Default w/o overrides | |
python version = 2.7.13 (default, Dec 18 2016, 07:03:34) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment