Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save agaffney/9807fe04f4a19263392cb340b780dcaa to your computer and use it in GitHub Desktop.
Save agaffney/9807fe04f4a19263392cb340b780dcaa to your computer and use it in GitHub Desktop.
Simple example for composing complex vars by generating YAML using an inline template
---
- hosts: localhost
gather_facts: no
tasks:
- name: do some stuff
vars:
temp_var: |
{% for i in range(1, 5) %}
- {{ i }}
{% endfor %}
debug:
msg: '{{ temp_var | from_yaml }}'
@agaffney
Copy link
Author

agaffney commented May 9, 2018

This playbook dynamically creates a list in YAML using jinja templating, and then uses | from_yaml to convert that YAML to native types. You could alternatively have the content of the temp_var variable in a separate .j2 file and then use

{{ lookup('template', 'path/to/template.j2') | from_yaml }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment