Skip to content

Instantly share code, notes, and snippets.

@kevduggan
Created January 5, 2016 16:25
Show Gist options
  • Save kevduggan/b9960818d886c34b2660 to your computer and use it in GitHub Desktop.
Save kevduggan/b9960818d886c34b2660 to your computer and use it in GitHub Desktop.
maps ec2 facts to host vars
#
# maps the hostvars from ec2 tags in the dynamic inventory to the var names expected by our roles
# this allows us to have no host var files and alsonot have host specific vars in the group_vars files as these are only evaluated in the scope
# of the current host the play is being applied to i.e. all host dont have a seperate copy of all the facts.
# this leads to a dangerous situation when using jinja2 loops over nodes in groups and then accessing hostvars
# (that have been set in the groupvars) for that node
#
- hosts: all
tasks:
- set_fact: HOST_IP="{{ ec2_private_ip_address }}" ansible_ssh_host="{{ inventory_hostname }}"
- hosts: zookeeper
tasks:
- set_fact: ZOOKEEPER_SERVER_ID="{{ ec2_tag_zookeeper_server_id }}"
- hosts: kafka
tasks:
- set_fact: KAFKA_BROKER_ID="{{ ec2_tag_kafka_broker_id }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment