Skip to content

Instantly share code, notes, and snippets.

@hslavchev
Created May 17, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hslavchev/44d84d33e0a04a61c9ff0d8325715b5a to your computer and use it in GitHub Desktop.
Save hslavchev/44d84d33e0a04a61c9ff0d8325715b5a to your computer and use it in GitHub Desktop.
---
- 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