Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- 2 - hosts: localhost
- 3 gather_facts: false
- 4 sudo: no
- 5
- 6
- 7 tasks:
- 8 - name: Get Instance id
- 9 local_action:
- 10 module: shell /usr/bin/list_instances -r us-east-1 -H ID,State,T:Name -t |grep "running" | awk '{print $1}'
- 11 register: instance_id
- 12 - name: Distplay Instance Id
- 13 debug: var=instance_id.stdout_lines
- 14
- 15 - name: Gather Facts
- 16 local_action:
- 17 module: ec2_remote_facts
- 18 region: "us-east-1"
- 19 aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
- 20 aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
- 21 filters:
- 22 instance-id: "{{ item }}"
- 23 with_items: instance_id.stdout_lines
- 24 register: ec2_facts
- 25
- 26 - name: debug facts
- 27 debug: var=ec2_facts.results[0]
- 28
- 29 - name: Create AMI
- 30 local_action:
- 31 module: ec2_ami
- 32 region: "us-east-1"
- 33 instance_id: "{{ item }}"
- 34 wait: yes
- 35 name: "{{ ec2_facts.results.instances.private_ip_address }}_{{ lookup('pipe', 'date +%Y%m%d') }}"
- 36 aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
- 37 aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
- 38 with_items: instance_id.stdout_lines·
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement