---
- fail:
    msg: "{{ item }} needs to be defined"
  when: "{{ item }} is not defined"
  with_items:
  - r_openshift_aws_ami_copy_src_ami
  - r_openshift_aws_ami_copy_name
  - r_openshift_aws_ami_copy_region

- name: "Create copied AMI image and wait: {{ r_openshift_aws_ami_copy_wait | default(False) }}"
  ec2_ami_copy:
    region: "{{ r_openshift_aws_ami_copy_region }}"
    source_region: "{{ r_openshift_aws_ami_copy_region }}"
    name: "{{ r_openshift_aws_ami_copy_name }}"
    source_image_id: "{{ r_openshift_aws_ami_copy_src_ami }}"
    encrypted: "{{ r_openshift_aws_ami_copy_encrypt | default(False) }}"
    kms_key_id: "{{ r_openshift_aws_ami_copy_kms_arn | default(omit) }}"
    wait: "{{ r_openshift_aws_ami_copy_wait | default(omit) }}"
    tags: "{{ r_openshift_aws_ami_copy_tags }}"
  register: copy_result

- debug: var=copy_result

- name: return AMI ID with setfact - openshift_aws_ami_copy_retval_custom_ami
  set_fact:
    r_openshift_aws_ami_copy_retval_custom_ami: "{{ copy_result.image_id }}"
