Created
October 2, 2014 20:46
-
-
Save vicenteg/e0465c8d6e784e2028d9 to your computer and use it in GitHub Desktop.
how do i access ec2_facts inside a template?
This file contains hidden or 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
Your Cluster | |
=== | |
You can access MCS at these addresses: | |
{% for webserver in groups['webserver'] %} | |
{%- if 'ansible_ec2_public_hostname' in ec2_facts.ansible_facts -%} | |
* https://{{hostvars[webserver].ec2_facts.ansible_facts.ansible_ec2_public_hostname}}:8443 | |
{%- else %} | |
* https://{{hostvars[webserver].ec2_facts.ansible_facts.ansible_ec2_local_ipv4}}:8443 | |
{%- endif %} | |
{% if not loop.last %} | |
or | |
{% endif %} | |
{% endfor %} |
This file contains hidden or 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
# register ec2 facts for host/group webserver. | |
# write a file containing some stuff. | |
- hosts: webserver | |
tasks: | |
- name: get ec2 facts | |
ec2_facts: | |
register: ec2_facts | |
when: '"instance_id" in hostvars[inventory_hostname]' | |
- name: write some cluster info out | |
local_action: template src=cluster_info.md.j2 dest=/tmp/cluster_info.md |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment