DCD-890: Start of ASG tag manipulation.

This commit is contained in:
Steve Smith
2020-01-13 13:31:06 +11:00
parent 510d152582
commit c4b524580d
2 changed files with 31 additions and 0 deletions

View File

@@ -24,5 +24,8 @@
notify:
- Restart CloudWatch Agent
- name: Store some metadata about this run
include_tasks: "write-tags.yml"
- name: Initiate the startup of any new AWS services now
meta: flush_handlers

View File

@@ -0,0 +1,28 @@
---
- name: Fetch local EC2 metadata
ec2_metadata_facts:
- name: Retrieve all available EC2 tags
ec2_tag:
region: "{{ ansible_ec2_placement_region }}"
resource: "{{ ansible_ec2_instance_id }}"
state: list
register: ec2_instance_tags
- name: Retrieve autoscaling group
set_fact:
ec2_autoscaling_group: "{{ ec2_tags.tags['aws:autoscaling:groupName']|default('') }}"
- block:
- name: Get AutoscalingGroup tags
command: "aws autoscaling describe-tags --filters Name=auto-scaling-group,Values='{{ ec2_autoscaling_group }}'"
register: asg_tags_out
- name: Parse and transform the AWS tags into a lookup table
set_fact:
asg_tags: "{{ (asg_tags_out.stdout | from_json).Tags | items2dict(key_name='Key', value_name='Value') }}"
when: ec2_autoscaling_group != ''