Skip to content

Instantly share code, notes, and snippets.

@abeyt
Forked from spiette/jinja_variables_types.yml
Last active September 21, 2017 10:11
Show Gist options
  • Save abeyt/13bf67b04bc23efb31cbe35e691df6d3 to your computer and use it in GitHub Desktop.
Save abeyt/13bf67b04bc23efb31cbe35e691df6d3 to your computer and use it in GitHub Desktop.

Revisions

  1. abeyt revised this gist Sep 21, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions jinja_variables_types.yml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ---
    #https://www.webforefront.com/django/usebuiltinjinjafilters.html
    - hosts: all
    gather_facts: no
    vars:
  2. @spiette spiette created this gist Mar 3, 2016.
    50 changes: 50 additions & 0 deletions jinja_variables_types.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    ---
    - hosts: all
    gather_facts: no
    vars:
    string: "string"
    list:
    - item1
    - item2
    dict:
    key1: value1
    key2: value2
    object:
    k1: "string"
    k2: [ "item1", "item2" ]
    k3: { 'i1': 'v1', 'i2': 'v2' }
    tasks:
    - debug: msg="dict is mapping"
    when: dict is mapping
    - debug: msg="list is mapping"
    when: list is mapping
    - debug: msg="string is mapping"
    when: string is mapping
    - debug: msg="dict is sequence"
    when: dict is sequence
    - debug: msg="list is sequence"
    when: list is sequence
    - debug: msg="string is sequence"
    when: string is sequence
    - debug: msg="dict is iterable"
    when: dict is iterable
    - debug: msg="list is iterable"
    when: list is iterable
    - debug: msg="string is iterable"
    when: string is iterable
    - debug: msg="dict is string"
    when: dict is string
    - debug: msg="list is string"
    when: list is string
    - debug: msg="string is string"
    when: string is string
    - copy:
    dest: /tmp/variable.txt
    content: |
    {% for k,v in object.iteritems() %}
    {% if v is string %}string: {{ v }}
    {% elif v is mapping %}{% for j,l in v.iteritems() %}{{ j }}: {{ l }}\n{% endfor %}
    {% elif v is sequence %}{% for n in v %}- {{ n }}\n{% endfor %}
    {% else %}huh?
    {% endif %}
    {% endfor %}