Skip to content

Instantly share code, notes, and snippets.

@droopy4096
Last active August 29, 2015 14:02
Show Gist options
  • Save droopy4096/ccd4b8415b1969a3e9bd to your computer and use it in GitHub Desktop.
Save droopy4096/ccd4b8415b1969a3e9bd to your computer and use it in GitHub Desktop.
Ansible Jinja variable issues
---
simple_var: "Simple var"
nested_var: "{{ simple_var }}"
fact_var: "{{ ansible_default_ipv4.address }}"
[keystone]
192.168.0.123 ansible_ssh_user=root
fact_var: "{{ ansible_default_ipv4.address }}"
---
- 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
{{ 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 %}
---
- hosts: keystone
roles:
- role: keystone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment