Skip to content

Instantly share code, notes, and snippets.

@vicenteg
Created October 2, 2014 20:46
Show Gist options
  • Save vicenteg/e0465c8d6e784e2028d9 to your computer and use it in GitHub Desktop.
Save vicenteg/e0465c8d6e784e2028d9 to your computer and use it in GitHub Desktop.
how do i access ec2_facts inside a template?
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 %}
# 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