From ef60e78a5d57b411dfaf726600f73e55f84ca20e Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Wed, 11 Jun 2025 13:02:25 +0200 Subject: [PATCH] Adding a task to stop if no AMI is found. --- roles/aws/aws_ec2_with_eip/tasks/main.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/roles/aws/aws_ec2_with_eip/tasks/main.yml b/roles/aws/aws_ec2_with_eip/tasks/main.yml index 09be043cc..37ef61a20 100644 --- a/roles/aws/aws_ec2_with_eip/tasks/main.yml +++ b/roles/aws/aws_ec2_with_eip/tasks/main.yml @@ -100,6 +100,11 @@ virtualization-type: "{{ aws_ec2_with_eip.ami_virtualization_type }}" register: _aws_ec2_with_eip_ami_images +- name: Quit if no AMI found. + ansible.builtin.fail: + msg: "No AMI found using the provided filters, exiting!" + when: _aws_ec2_with_eip_ami_images.images | length == 0 + # Do not create an instance if _aws_hostname is not an EC2 generated address unless `force: true` - name: Create new EC2 instance. amazon.aws.ec2_instance: