add_host scope from inside roles

Hi all,
I’m a bit confused about the behavior of add_host when used from inside a role or directly in the playbook.
Am I doing something wrong or am I just hitting some role’s scope boundary?

THIS WORKS (from the playbook)

The code is one playbook with three plays. It's not possible to put a
playbook "inside a role".

In particular, it's not possible to apply "hosts" in a "Role"
https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html#role

HTH,

  -vlado

Hi Vladimir,
thanks for pointing out that mistake.
I fixed the role, but I still have the same behaviour.
You can find below the full example with the output.

PLAYBOOK

this is just a variable named 'groupname'
  groupname: launched

Per the docs https://docs.ansible.com/ansible/latest/modules/add_host_module.html,
if you actually want to add it to the 'launched' group:

groups: launched

Hi Brian,
thanks a lot, that was indeed one part of the problem.

I also had to remove the meta: refresh_inventory at the end of the first play.

WORKING VERSION