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
• 380 points

edited Sep 9 by Latchu 532 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?
launching instance or creating bucket also very easy. Then why should we use ansible? Because here  i deploying automatically everything using jenkins+ansible+docker+kubernetes and some times using packer tool too.
Yeah well, if you're trying to automate everything then ansible is a good approach.

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.