I have a playbook where I’m launching some instances, adding them to a host group, doing package installs, then I want to bundle each instance with a unique image name. My first thought was to use an instance tag, but can’t seem to find how to read tags on a running instance. Should I use set_fact when I create the instance instead? Still getting my head around variable scoping.
Thanks!
Brian
roles/ec2_bundle_image/main.yaml:
name: Fetch the ec2_facts for the server
action: ec2_facts
name: Calculate the image name
action: set_fact ec2_image_name={{ NAME_TAG_GOES_HERE }}{{ ansible_ec2_profile }}{{ ansible_date_time[date] }}
name: Bundle the instance into an image
local_action: ec2_ami aws_access_key={{ aws_access_key }} aws_secret_key={{ aws_secret_key }}
instance_id={{ ansible_ec2_instance_id }} wait=yes
name={{ ec2_image_name }}
I didn’t realize I could add arbitrary variables during add_host, so I think I can just set ec2_image_name to what I want in the add_host action when I start the instances.
Otherwise, I don’t see a way to list the tags associated with an instance.