mirror of
https://bitbucket.org/atlassian/dc-deployments-automation.git
synced 2025-12-14 00:43:06 -06:00
Merged in DCD-890-aws-tagging (pull request #73)
DCD-890: Tag EC2/ASG with runtime metadata Approved-by: Ben Partridge <bpartridge@atlassian.com>
This commit is contained in:
@@ -16,6 +16,8 @@ provisioner:
|
|||||||
name: ansible
|
name: ansible
|
||||||
lint:
|
lint:
|
||||||
name: ansible-lint
|
name: ansible-lint
|
||||||
|
options:
|
||||||
|
x: ["303", "602"]
|
||||||
inventory:
|
inventory:
|
||||||
links:
|
links:
|
||||||
group_vars: ../../../../group_vars/
|
group_vars: ../../../../group_vars/
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ provisioner:
|
|||||||
name: ansible
|
name: ansible
|
||||||
lint:
|
lint:
|
||||||
name: ansible-lint
|
name: ansible-lint
|
||||||
|
options:
|
||||||
|
x: ["303", "602"]
|
||||||
inventory:
|
inventory:
|
||||||
links:
|
links:
|
||||||
group_vars: ../../../../group_vars/
|
group_vars: ../../../../group_vars/
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ provisioner:
|
|||||||
name: ansible
|
name: ansible
|
||||||
lint:
|
lint:
|
||||||
name: ansible-lint
|
name: ansible-lint
|
||||||
|
options:
|
||||||
|
x: ["303", "602"]
|
||||||
inventory:
|
inventory:
|
||||||
links:
|
links:
|
||||||
group_vars: ../../../../group_vars/
|
group_vars: ../../../../group_vars/
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
- name: Install AWS support packages
|
- name: Install AWS support packages
|
||||||
yum:
|
yum:
|
||||||
name:
|
name:
|
||||||
- ec2-utils
|
|
||||||
- amazon-ssm-agent
|
|
||||||
- amazon-efs-utils
|
- amazon-efs-utils
|
||||||
|
- amazon-ssm-agent
|
||||||
|
- awscli
|
||||||
|
- git
|
||||||
|
- ec2-utils
|
||||||
|
|
||||||
- name: Install CloudWatch Agent
|
- name: Install CloudWatch Agent
|
||||||
yum:
|
yum:
|
||||||
|
|||||||
@@ -24,5 +24,8 @@
|
|||||||
notify:
|
notify:
|
||||||
- Restart CloudWatch Agent
|
- 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
|
- name: Initiate the startup of any new AWS services now
|
||||||
meta: flush_handlers
|
meta: flush_handlers
|
||||||
|
|||||||
60
roles/aws_common/tasks/write-tags.yml
Normal file
60
roles/aws_common/tasks/write-tags.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Retrieve all available EC2 tags
|
||||||
|
ec2_tag:
|
||||||
|
region: "{{ ansible_ec2_placement_region }}"
|
||||||
|
resource: "{{ ansible_ec2_instance_id }}"
|
||||||
|
state: list
|
||||||
|
register: ec2_instance_tags
|
||||||
|
ignore_errors: true
|
||||||
|
tags:
|
||||||
|
- notest
|
||||||
|
|
||||||
|
- name: Retrieve autoscaling group
|
||||||
|
set_fact:
|
||||||
|
ec2_autoscaling_group: "{{ ec2_tags.tags['aws:autoscaling:groupName'] | default('') }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
# No existing timestamp, so this is a first run. Persist some metadata into the ASG.
|
||||||
|
- name: Fetch the git revision for this repo
|
||||||
|
command:
|
||||||
|
cmd: git rev-parse HEAD
|
||||||
|
register: git_out
|
||||||
|
|
||||||
|
- name: Setup the new ASG tags
|
||||||
|
set_fact:
|
||||||
|
deployment_firstrun_meta:
|
||||||
|
- ResourceType: "auto-scaling-group"
|
||||||
|
ResourceId: "{{ ec2_autoscaling_group }}"
|
||||||
|
PropagateAtLaunch: true
|
||||||
|
Key: "atl:deployment:commit"
|
||||||
|
Value: "{{ git_out.stdout }}"
|
||||||
|
|
||||||
|
- ResourceType: "auto-scaling-group"
|
||||||
|
ResourceId: "{{ ec2_autoscaling_group }}"
|
||||||
|
PropagateAtLaunch: true
|
||||||
|
Key: "atl:deployment:first-run"
|
||||||
|
Value: "{{ ansible_date_time.iso8601 }}"
|
||||||
|
|
||||||
|
# Set the tags on the ASG and the local instance. We need to
|
||||||
|
# ignore errors as it's possible we don't have the permissions,
|
||||||
|
# and we can't check up-front.
|
||||||
|
- name: Set the first-run tags on the ASG ("FAIL" is not critical)
|
||||||
|
command: "aws autoscaling
|
||||||
|
create-or-update-tags
|
||||||
|
--region {{ ansible_ec2_placement_region }}
|
||||||
|
--tags '{{ deployment_firstrun_meta | to_json }}'"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Set the tags on the local instance ("FAIL" is not critical)
|
||||||
|
ec2_tag:
|
||||||
|
region: "{{ ansible_ec2_placement_region }}"
|
||||||
|
resource: "{{ ansible_ec2_instance_id }}"
|
||||||
|
tags:
|
||||||
|
"atl:deployment:commit": "{{ git_out.stdout }}"
|
||||||
|
"atl:deployment:first-run": "{{ ansible_date_time.iso8601 }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
when:
|
||||||
|
- ec2_autoscaling_group != ''
|
||||||
|
- ec2_instance_tags.tags['atl:deployment:first-run'] is not defined
|
||||||
Reference in New Issue
Block a user