How to create AMI from running instance using ansible?

0 votes
Hi, I need to take AMI(amazon machine image-clone of running instance) from running aws ubuntu instance using ansible playbook. I have one aws ec2 ubuntu instance. So i have to take image of Server weekly once. How to achieve this using ansible-playbook?
Sep 9 in Ansible by Latchu
• 270 points

edited Sep 9 by Latchu 41 views
Hey @Latchu, can you please describe what you mean by "take the AMI"?
Hi Kalgi,

i have found the solution as well created ansible-playbook. Its successfully created. Thanks pa. Below is ansible-playbook to create ami from ec2-instance.

---
- hosts: localhost
  connection: local
  become: yes
  gather_facts: no
  vars:
    region: us-east-1
    ins_name: Sample
    ami_name: Sample
  tasks:
    - name: To Get Instance Id
      command: "aws ec2 describe-instances
                --filters Name=tag:Name,Values={{ ins_name }}
                --query 'Reservations[0].Instances[0].InstanceId'
                --output text"
      register: instanceid

    - name: To Create AMI
      ec2_ami:
     --query 'Reservations[0].Instances[0].InstanceId'

What does this do?

Cloning an instance is very easily done using the console. Why use ansible?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.