seal_ami.yml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ---
  2. - name: fetch newly created instances
  3. ec2_instance_facts:
  4. region: "{{ openshift_aws_region }}"
  5. filters:
  6. "tag:Name": "{{ openshift_aws_base_ami_name }}"
  7. instance-state-name: running
  8. register: instancesout
  9. retries: 20
  10. delay: 3
  11. until: instancesout.instances|length > 0
  12. - name: fetch the ami used to create the instance
  13. ec2_ami_find:
  14. region: "{{ openshift_aws_region }}"
  15. ami_id: "{{ instancesout.instances[0]['image_id'] }}"
  16. register: original_ami_out
  17. retries: 20
  18. delay: 3
  19. until: original_ami_out.results|length > 0
  20. - name: combine the tags of the original ami with newly created ami
  21. set_fact:
  22. l_openshift_aws_ami_tags: "{{ original_ami_out.results[0]['tags'] | combine(openshift_aws_ami_tags) }}"
  23. - name: bundle ami
  24. ec2_ami:
  25. instance_id: "{{ instancesout.instances.0.instance_id }}"
  26. region: "{{ openshift_aws_region }}"
  27. state: present
  28. description: "This was provisioned {{ ansible_date_time.iso8601 }}"
  29. name: "{{ openshift_aws_ami_name }}"
  30. tags: "{{ l_openshift_aws_ami_tags }}"
  31. wait: yes
  32. register: amioutput
  33. - debug: var=amioutput
  34. - when: openshift_aws_ami_encrypt | bool
  35. block:
  36. - name: augment the encrypted ami tags with source-ami
  37. set_fact:
  38. source_tag:
  39. source-ami: "{{ amioutput.image_id }}"
  40. - name: copy the ami for encrypted disks
  41. include_tasks: ami_copy.yml
  42. vars:
  43. openshift_aws_ami_copy_name: "{{ openshift_aws_ami_name }}-encrypted"
  44. openshift_aws_ami_copy_src_ami: "{{ amioutput.image_id }}"
  45. # TODO: How does the kms alias get passed to ec2_ami_copy
  46. openshift_aws_ami_copy_kms_alias: "alias/{{ openshift_aws_clusterid }}_kms"
  47. openshift_aws_ami_copy_tags: "{{ source_tag | combine(openshift_aws_ami_tags) }}"
  48. # this option currently fails due to boto waiters
  49. # when supported this need to be reapplied
  50. #openshift_aws_ami_copy_wait: True
  51. - name: terminate temporary instance
  52. ec2:
  53. state: absent
  54. region: "{{ openshift_aws_region }}"
  55. instance_ids: "{{ instancesout.instances.0.instance_id }}"