DCD-890: Simplify tagging logic.

This commit is contained in:
Steve Smith
2020-01-14 11:14:36 +11:00
parent 590eca6aa5
commit ce52f34742

View File

@@ -9,50 +9,37 @@
- name: Retrieve autoscaling group - name: Retrieve autoscaling group
set_fact: set_fact:
ec2_autoscaling_group: "{{ ec2_tags.tags['aws:autoscaling:groupName']|default('') }}" ec2_autoscaling_group: "{{ ec2_tags.tags['aws:autoscaling:groupName'] | default('') }}"
- block: - block:
# We're in an ASG, lookup the tags... # No existing timestamp, so this is a first run. Persist some metadata into the ASG.
- name: Get AutoscalingGroup tags - name: Fetch the git revision for this repo
command: "aws autoscaling command:
describe-tags cmd: git rev-parse HEAD
--region {{ ansible_ec2_placement_region }} register: git_out
--filters Name=auto-scaling-group,Values='{{ ec2_autoscaling_group }}'"
register: asg_tags_out
- name: Parse and transform the AWS tags into a lookup table - name: Setup the new ASG tags
set_fact: set_fact:
asg_tags: "{{ (asg_tags_out.stdout | from_json).Tags | items2dict(key_name='Key', value_name='Value') }}" deployment_firstrun_meta:
- ResourceType: "auto-scaling-group"
ResourceId: "{{ ec2_autoscaling_group }}"
PropagateAtLaunch: true
Key: "atl:deployment:commit"
Value: "{{ git_out.stdout }}"
- block: - ResourceType: "auto-scaling-group"
# No existing timestamp, so this is a first run. Persist some metadata into the ASG. ResourceId: "{{ ec2_autoscaling_group }}"
- name: Fetch the git revision for this repo PropagateAtLaunch: true
command: Key: "atl:deployment:first-run"
cmd: git rev-parse HEAD Value: "{{ ansible_date_time.iso8601 }}"
register: git_out
- name: Setup the new ASG tags - name: Set the first-run tags on the ASG
set_fact: command: "aws autoscaling
deployment_firstrun_meta: create-or-update-tags
- ResourceType: "auto-scaling-group" --region {{ ansible_ec2_placement_region }}
ResourceId: "{{ ec2_autoscaling_group }}" --tags '{{ deployment_firstrun_meta | to_json }}'"
PropagateAtLaunch: true
Key: "atl:deployment:commit"
Value: "{{ git_out.stdout }}"
- ResourceType: "auto-scaling-group" when:
ResourceId: "{{ ec2_autoscaling_group }}" - ec2_autoscaling_group != ''
PropagateAtLaunch: true - ec2_instance_tags.tags['atl:deployment:first-run'] is not defined
Key: "atl:deployment:first-run"
Value: "{{ ansible_date_time.iso8601 }}"
- name: Set the first-run tags on the ASG
command: "aws autoscaling
create-or-update-tags
--region {{ ansible_ec2_placement_region }}
--tags '{{ deployment_firstrun_meta | to_json }}'"
when: asg_tags['atl:deployment:first-run'] is not defined
when: ec2_autoscaling_group != ''
ignore_errors: true ignore_errors: true