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 }}