summaryrefslogtreecommitdiffstats
path: root/roles/openshift_aws/tasks/seal_ami.yml
blob: c1cb37a3bcaa3170f983493206914ba06d7d8ac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
---
- name: fetch newly created instances
  ec2_instance_facts:
    region: "{{ openshift_aws_region }}"
    filters:
      "tag:Name": "{{ openshift_aws_base_ami_name }}"
      instance-state-name: running
  register: instancesout
  retries: 20
  delay: 3
  until: instancesout.instances|length > 0

- name: fetch the ami used to create the instance
  ec2_ami_find:
    region: "{{ openshift_aws_region }}"
    ami_id: "{{ instancesout.instances[0]['image_id'] }}"
  register: original_ami_out
  retries: 20
  delay: 3
  until: original_ami_out.results|length > 0

- name: combine the tags of the original ami with newly created ami
  set_fact:
    l_openshift_aws_ami_tags: "{{ original_ami_out.results[0]['tags'] | combine(openshift_aws_ami_tags) }}"

- name: bundle ami
  ec2_ami:
    instance_id: "{{ instancesout.instances.0.instance_id }}"
    region: "{{ openshift_aws_region }}"
    state: present
    description: "This was provisioned {{ ansible_date_time.iso8601 }}"
    name: "{{ openshift_aws_ami_name }}"
    tags: "{{ l_openshift_aws_ami_tags }}"
    wait: yes
  register: amioutput

- debug: var=amioutput

- when: openshift_aws_ami_encrypt | bool
  block:
  - name: augment the encrypted ami tags with source-ami
    set_fact:
      source_tag:
        source-ami: "{{ amioutput.image_id }}"

  - name: copy the ami for encrypted disks
    include_tasks: ami_copy.yml
    vars:
      openshift_aws_ami_copy_name: "{{ openshift_aws_ami_name }}-encrypted"
      openshift_aws_ami_copy_src_ami: "{{ amioutput.image_id }}"
      # TODO: How does the kms alias get passed to ec2_ami_copy
      openshift_aws_ami_copy_kms_alias: "alias/{{ openshift_aws_clusterid }}_kms"
      openshift_aws_ami_copy_tags: "{{ source_tag | combine(openshift_aws_ami_tags) }}"
      # this option currently fails due to boto waiters
      # when supported this need to be reapplied
      #openshift_aws_ami_copy_wait: True

- name: terminate temporary instance
  ec2:
    state: absent
    region: "{{ openshift_aws_region }}"
    instance_ids: "{{ instancesout.instances.0.instance_id }}"