Is there any way to write a module that does 'remove_host' or 'replace_hosts'?

I have plays that look like, eg

`

  • name: provision ec2 instance

  • set_fact:
    newly_created_ips: …

  • import_playbook: …/configure/nomad-server.yml
    `

Inside nomad-server.yml it looks like

`

  • name: Configure nomad-client
    hosts: nomad_client

    `

What I want is to “dynamically” limit the inventory in nomad-client.yml to the set of hosts that actually just got created – not the full set of hosts that match nomad_client.

I could of course create a complicated hosts pattern or use a variable. That makes using the nomad-server.yml playbook more complex in other contexts.

What I really want to do is something akin to

`

  • set_fact:
    groups[‘nomad_client’]: “{{ newly_created_ips }}”
    `

Of course the above does not work, but it shows the intent.

Can I create a module that has access to the inventory plugin being used? Or is there some way to “tell” the ec2 inventory plugin to change the set of hosts in nomad_server for the remainder of the play (maybe having to run -meta: refresh_inventory afterwords).

No, it requires core code modifications.

Bummer, but thanks Brian.