Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
---
- 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
You can’t perform that action at this time.