Skip to content

Instantly share code, notes, and snippets.

@naavveenn
Created March 16, 2018 19:26
Show Gist options
  • Save naavveenn/679941ee97a5b85e6d2eaf8622232d35 to your computer and use it in GitHub Desktop.
Save naavveenn/679941ee97a5b85e6d2eaf8622232d35 to your computer and use it in GitHub Desktop.
---
#Creating an AMI based on time but need to schedule this job on Ansible-Tower based on intervals
- hosts: local
connection: local
gather_facts: no
vars:
aws_region: ap-south-1
tasks:
- name: Getting the facts of the system
setup: filter=ansible_date_time
register: ansible_date_time
- debug:
var: ansible_date_time
- name: Get the instance id
ec2_instance_facts:
region: "{{ aws_region }}"
register: ec2
- name: Creating an AMI
shell: aws ec2 create-image --instance-id {{ item.instance_id }} --name "AMI-{{ item.instance_id }}-{{ ansible_date_time.epoch }}" --region {{ aws_region }}
with_items:
- "{{ ec2.instances }}"
register: ami_out
- debug:
var: ami_out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment