I have a playbook which creates a new container and run commands in it.
Once the container is created there is a second play in the playbook which references the container as the host. When the second play runs it causes skipping: no hosts matched
.
This is very likely due to the new container not being in Ansible's hosts inventory file.
How can newly created containers be added to the Ansible's hosts OR how can Ansible run commands on containers which are not in Ansible's hosts file?
Ansible plays run on targets which must be defined in the inventory. For hosts which are created dynamically, you can create an in-memory inventory.
See add_host
module. You can define the same properties as in the inventory file.