# Is there any way to write a module that does 'remove\_host' or 'replace\_hosts'?

**URL:** <https://forum.ansible.com/t/is-there-any-way-to-write-a-module-that-does-remove-host-or-replace-hosts/29029>\
**Category:** Ansible Project\
**Created:** [November 14, 2018, 4:45pm UTC](https://forum.ansible.com/t/is-there-any-way-to-write-a-module-that-does-remove-host-or-replace-hosts/29029 "2018-11-14T16:45:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [November 14, 2018, 4:45pm UTC](https://forum.ansible.com/t/is-there-any-way-to-write-a-module-that-does-remove-host-or-replace-hosts/29029/1 "2018-11-14T16:45:22Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 14, 2018, 4:48pm UTC](https://forum.ansible.com/t/is-there-any-way-to-write-a-module-that-does-remove-host-or-replace-hosts/29029/2 "2018-11-14T16:48:51Z")

</div>

No, it requires core code modifications.

---

<div class="post-metadata">

**Author:** ![Barry\_Kaplan](https://avatars.discourse-cdn.com/v4/letter/b/48db29/32.png) [@Barry\_Kaplan](https://forum.ansible.com/u/Barry_Kaplan)\
**Post date:** [November 14, 2018, 4:56pm UTC](https://forum.ansible.com/t/is-there-any-way-to-write-a-module-that-does-remove-host-or-replace-hosts/29029/3 "2018-11-14T16:56:36Z")

</div>

Bummer, but thanks Brian.
