Skip to content

Instantly share code, notes, and snippets.

@dgulinobw
Created January 9, 2017 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgulinobw/14d7bf0745c09f50732ca911a008de7a to your computer and use it in GitHub Desktop.
Save dgulinobw/14d7bf0745c09f50732ca911a008de7a to your computer and use it in GitHub Desktop.
Way to test ansible jinja templates (.j2) independently from playbooks
#add local to existing ansible hosts, to get variable from your hosts
[local]
127.0.0.1
[app]
test1 app_name=app1
test2 app_name=app2
{vm_endpoints, [{% for host in groups['app'] %} "{{ hostvars[host]['app_name']}}" {% if not loop.last %}, {% endif %}{% endfor %}]}.
#!/bin/bash
#example invocation:
ansible-playbook -i hosts --check --diff --connection=local test.yml
---
- hosts: 127.0.0.1
connection: local
tasks:
- name: Test jinja2template
template: src=test.j2 dest=test.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment