Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active May 1, 2021 15:45
Show Gist options
  • Save halberom/ef3ea6d6764e929923b0888740e05211 to your computer and use it in GitHub Desktop.
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
# play.yml
---
- hosts: localhost
connection: local
gather_facts: False
roles:
- test
# roles/test/tasks/main.yml
---
- include_vars:
file: subdir/bar
name: foo
- debug:
var: foo
# roles/test/vars/subdir/bar
---
mysuperduperdict:
key1:
- abc
- def
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
$ 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