Created
May 17, 2019 21:29
-
-
Save hslavchev/44d84d33e0a04a61c9ff0d8325715b5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
vars: | |
aws_region: us-east-1 | |
vars_prompt: | |
- name: "new_ami" | |
prompt: "What is the new AMI id?" | |
private: no | |
tasks: | |
- debug: | |
msg: "New AMI id is {{ new_ami }}" | |
- ec2_ami_find: | |
is_public: no | |
region: "{{ aws_region }}" | |
ami_tags: | |
ansible: "true" | |
vpc_support: "true" | |
env: "prod" | |
no_result_action: fail | |
register: ami_find | |
- name: set old ami variable | |
set_fact: | |
old_ami: "{{ item.ami_id }}" | |
with_items: "{{ ami_find.results }}" | |
loop_control: | |
label: "{{ item.ami_id }}" | |
- name: remove tags from old ami | |
ec2_tag: | |
region: "{{ aws_region }}" | |
resource: "{{ old_ami }}" | |
tags: | |
Name: "Demoted on {{ ansible_date_time.date }}" | |
env: "" | |
- name: promote new ami to prod | |
ec2_tag: | |
region: "{{ aws_region }}" | |
resource: "{{ new_ami }}" | |
state: present | |
tags: | |
Name: latest | |
ansible: "true" | |
vpc_support: "true" | |
env: "prod" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment