diff --git a/plays/aws_ec2_standalone/ec2.yml b/plays/aws_ec2_standalone/ec2.yml index bab077c83..e64a9c7c7 100644 --- a/plays/aws_ec2_standalone/ec2.yml +++ b/plays/aws_ec2_standalone/ec2.yml @@ -1,6 +1,6 @@ --- # First step. Spin up a "blank" instance and add the controller user and Ansible via user-data. -- hosts: "_{{ _aws_resource_name | regex_replace('-', '_') }}" +- hosts: "{{ _aws_resource_name }}" connection: local become: false diff --git a/plays/aws_ec2_standalone/launch.yml b/plays/aws_ec2_standalone/launch.yml index cb1ed7373..c10de7bc7 100644 --- a/plays/aws_ec2_standalone/launch.yml +++ b/plays/aws_ec2_standalone/launch.yml @@ -25,8 +25,8 @@ - "_{{ _aws_resource_name | regex_replace('-', '_') }}" - name: If an Ansible host is not found, create it so we can execute EC2 orchestration. ansible.builtin.add_host: - name: "_{{ _aws_resource_name | regex_replace('-', '_') }}" + name: "{{ _aws_resource_name }}" groups: "_new_servers" - when: _aws_hostname | length == 0 + when: _aws_hostname|length == 0 - ansible.builtin.import_role: name: _exit diff --git a/roles/aws/aws_ec2_with_eip/tasks/main.yml b/roles/aws/aws_ec2_with_eip/tasks/main.yml index 6ac8dee5a..4739abf52 100644 --- a/roles/aws/aws_ec2_with_eip/tasks/main.yml +++ b/roles/aws/aws_ec2_with_eip/tasks/main.yml @@ -109,7 +109,7 @@ 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` +# Create an instance if _aws_hostname is set (it cannot be unless there is an EC2 generated address in a tagged hostgroup) unless `force: true` - name: Create new EC2 instance. amazon.aws.ec2_instance: profile: "{{ aws_ec2_with_eip.aws_profile }}" @@ -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_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 not aws_ec2_with_eip.force - name: Check if we have an existing EIP. amazon.aws.ec2_eip_info: