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

14 views
Skip to first unread message

Barry Kaplan

unread,
Nov 14, 2018, 11:45:22 AM11/14/18
to Ansible Project
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).

Brian Coca

unread,
Nov 14, 2018, 11:49:13 AM11/14/18
to ansible...@googlegroups.com
No, it requires core code modifications.


--
----------
Brian Coca

Barry Kaplan

unread,
Nov 14, 2018, 11:56:36 AM11/14/18
to Ansible Project
Bummer, but thanks Brian.
Reply all
Reply to author
Forward
0 new messages