Advertisement
Guest User

Untitled

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