Last active
August 29, 2015 14:02
-
-
Save droopy4096/ccd4b8415b1969a3e9bd to your computer and use it in GitHub Desktop.
Ansible Jinja variable issues
This file contains 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
--- | |
simple_var: "Simple var" | |
nested_var: "{{ simple_var }}" | |
fact_var: "{{ ansible_default_ipv4.address }}" |
This file contains 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
[keystone] | |
192.168.0.123 ansible_ssh_user=root |
This file contains 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
fact_var: "{{ ansible_default_ipv4.address }}" |
This file contains 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
--- | |
- name: test template | |
template: src=template.j2 dest=/tmp/template.txt | |
- name: test simple var | |
debug: var=simple_var | |
- name: test nested var | |
debug: var=nested_var | |
- name: test fact var | |
debug: var=fact_var |
This file contains 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
{{ simple_var }} | |
{{ nested_var }} | |
{{ fact_var }} | |
Var extraction: | |
{% for h in groups['keystone'] %} | |
{% set myvars=hostvars[h] %} | |
{{ myvars.simple_var }} | |
{{ myvars.nested_var }} | |
{{ myvars.fact_var }} | |
{{ myvars.ansible_default_ipv4.address }} | |
{% endfor %} |
This file contains 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
--- | |
- hosts: keystone | |
roles: | |
- role: keystone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment