Created
January 9, 2017 19:14
-
-
Save dgulinobw/14d7bf0745c09f50732ca911a008de7a to your computer and use it in GitHub Desktop.
Way to test ansible jinja templates (.j2) independently from playbooks
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
#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 |
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
{vm_endpoints, [{% for host in groups['app'] %} "{{ hostvars[host]['app_name']}}" {% if not loop.last %}, {% endif %}{% 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
#!/bin/bash | |
#example invocation: | |
ansible-playbook -i hosts --check --diff --connection=local test.yml |
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: 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