diff --git a/plays/aws_ec2_standalone/ec2.yml b/plays/aws_ec2_standalone/ec2.yml index e64a9c7c7..be2bd41e7 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 }}" +- hosts: "{{ _aws_resource_name }}, _{{ _aws_resource_name | regex_replace('-', '_') }}" connection: local become: false diff --git a/plays/aws_ec2_standalone/launch.yml b/plays/aws_ec2_standalone/launch.yml index 5f207ca44..c10de7bc7 100644 --- a/plays/aws_ec2_standalone/launch.yml +++ b/plays/aws_ec2_standalone/launch.yml @@ -27,6 +27,6 @@ ansible.builtin.add_host: 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 d03ddcc5c..4739abf52 100644 --- a/roles/aws/aws_ec2_with_eip/tasks/main.yml +++ b/roles/aws/aws_ec2_with_eip/tasks/main.yml @@ -17,6 +17,10 @@ with_inventory_hostnames: - "_{{ aws_ec2_with_eip.hostname|regex_replace('-', '_') }}" +- name: Check the hostname. + ansible.builtin.debug: + msg: "Ansible hostname set to: {{ _aws_hostname }}" + # Subnet ID is stored in ce-provision's data directory - name: Ensure server data directory exists. ansible.builtin.file: @@ -105,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 }}"