diff --git a/roles/aws/aws_ec2_with_eip/tasks/main.yml b/roles/aws/aws_ec2_with_eip/tasks/main.yml index 224d4b5c6..6ac8dee5a 100644 --- a/roles/aws/aws_ec2_with_eip/tasks/main.yml +++ b/roles/aws/aws_ec2_with_eip/tasks/main.yml @@ -137,7 +137,7 @@ volume_type: "{{ aws_ec2_with_eip.root_volume_type }}" encrypted: "{{ aws_ec2_with_eip.root_volume_encrypted }}" register: _aws_ec2_with_eip_instances - when: (_aws_hostname|length == 0) or (_aws_hostname == aws_ec2_with_eip.hostname|regex_replace('-', '_')) or aws_ec2_with_eip.force + when: (_aws_hostname|length == 0) or (_aws_hostname == '_' + aws_ec2_with_eip.hostname|regex_replace('-', '_')) or aws_ec2_with_eip.force # This task deliberately omits `image_id` so it cannot create a new instance, only refresh the state of an existing one. - name: Refresh EC2 instance. @@ -163,7 +163,7 @@ volume_type: "{{ aws_ec2_with_eip.root_volume_type }}" encrypted: "{{ aws_ec2_with_eip.root_volume_encrypted }}" register: _aws_ec2_with_eip_instances - when: (_aws_hostname|length > 0) or (_aws_hostname != aws_ec2_with_eip.hostname|regex_replace('-', '_')) or not aws_ec2_with_eip.force + when: (_aws_hostname|length > 0) or (_aws_hostname != '_' + aws_ec2_with_eip.hostname|regex_replace('-', '_')) or not aws_ec2_with_eip.force - name: Check if we have an existing EIP. amazon.aws.ec2_eip_info: