mirror of
https://github.com/ansible-collections/hetzner.hcloud.git
synced 2026-02-04 08:01:49 +00:00
feat(inventory): add all private networks as variables (#186)
This can be used in the `compose`, `groups` and `keyed_groups` settings to dynamically build the inventory. It also makes it possible for the user to override the `ansible_host` in `compose`, based on wether or not the server has a public ipv4 address, with fallback to the address in a specific private network.
This commit is contained in:
parent
9bc9949869
commit
83094a121d
2 changed files with 12 additions and 0 deletions
|
|
@ -222,8 +222,18 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
self.inventory.set_variable(server.name, "ipv6_network", to_native(server.public_net.ipv6.network))
|
||||
self.inventory.set_variable(server.name, "ipv6_network_mask", to_native(server.public_net.ipv6.network_mask))
|
||||
|
||||
self.inventory.set_variable(
|
||||
server.name,
|
||||
"private_networks",
|
||||
[
|
||||
{"name": n.network.name, "id": n.network.id, "ip": n.ip}
|
||||
for n in server.private_net
|
||||
],
|
||||
)
|
||||
|
||||
if self.get_option("network"):
|
||||
for server_private_network in server.private_net:
|
||||
# Set private_ipv4 if user filtered for one network
|
||||
if server_private_network.network.id == self.network.id:
|
||||
self.inventory.set_variable(server.name, "private_ipv4", to_native(server_private_network.ip))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue