Skip to content

Commit

Permalink
fix: test_customized_ami when trying to create existing AMI with
Browse files Browse the repository at this point in the history
custom_ami_recreate_if_exists set to ``false``
  • Loading branch information
abikouo committed Jul 20, 2023
1 parent 419e0d3 commit f8caf2d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
22 changes: 20 additions & 2 deletions roles/customized_ami/tasks/create.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
---
- name: List existing AMI by name
amazon.aws.ec2_ami_info:
filters:
name: "{{ custom_ami_name }}"
register: customized_ami__existing_amis

- name: Delete existing images
ansible.builtin.include_tasks: delete.yaml
amazon.aws.ec2_ami:
name: "{{ item.name }}"
image_id: "{{ item.image_id }}"
wait: true
state: absent
with_items: "{{ customized_ami__existing_amis.images }}"
when: custom_ami_recreate_if_exists | bool

- name: List existing AMI by name
amazon.aws.ec2_ami_info:
filters:
name: "{{ custom_ami_name }}"
register: customized_ami__existing_amis

- name: Create custom AMI
when: customized_ami__existing_amis.images | length == 0
block:
- name: Get Source AMI identifier
ansible.builtin.include_tasks: read_source_ami.yaml
Expand All @@ -22,4 +41,3 @@
msg: "Existing AMI found with name: '{{ custom_ami_name }}'"
when:
- customized_ami__existing_amis.images | length > 0
- not (custom_ami_recreate_if_exists | bool)
3 changes: 0 additions & 3 deletions roles/customized_ami/tasks/delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@
wait: true
state: absent
with_items: "{{ customized_ami__existing_amis.images }}"
when:
- customized_ami__existing_amis.images | length > 0
- (custom_ami_operation == 'create') | ternary(custom_ami_recreate_if_exists, 'true') | bool

0 comments on commit f8caf2d

Please sign in to comment.