Problem with "Skipping: No hosts matched" when using add_host and groups

Hello,

I’m launching an AWS instance and setting that instances’ new public IP address to a variable, and attempting to add that host to a group. Later in the same play, I use that group name in the topology.yml to remotely configure it.

I successfully get the IP address from the newly created instanced:

#Set the CoreA public IP to a var and use it to configure the remote host

  • set_fact:
    corea_public_ip: “{{ instance_public_ip.stdout }}”
  • add_host:
    name: “{{ corea_public_ip }}”
    groups: corea_launched

Later in the same play, I want to use that new group (corea_launched) var to connect to it:

  • name: Configure the Core Node A
    hosts: corea_launched
    become_user: sudo
    become_method: sudo
    roles:

  • role: configure_coreA

Once it gets to that part of the play it skips over and says no hosts matched.

I know that the add_host is working:

TASK [provision_instances : add_host] **************************************************************************************************************************************************************************

task path: /roles/provision_instances/tasks/corea_lc.yml:86

creating host via ‘add_host’: hostname=34.XX.XX.XX

changed: [local] => {

“add_host”: {

“groups”: [

“corea_launched”

],

“host_name”: “34.XX.XX.XX”,

“host_vars”: {}

},

“changed”: true

}

META: ran handlers

META: ran handlers

PLAY [Configure the Core Node A] **************************************************************************************************************************************************************************

skipping: no hosts matched

I’ve tried both with and without [corea_launched] group name in my hosts file.

Thanks in advance!