mirror of
https://github.com/ansible-collections/hetzner.hcloud
synced 2024-11-10 06:34:13 +00:00
Inventory Plugin: Add support for changing the name of the top level group all servers are added to (#164)
Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de> Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
This commit is contained in:
parent
2623b75b10
commit
d1c97c7e89
2 changed files with 10 additions and 5 deletions
2
changelogs/fragments/hcloud_inventory.yml
Normal file
2
changelogs/fragments/hcloud_inventory.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- dynamic inventory - add support changing the name of the top level group all servers are added to
|
|
@ -26,6 +26,11 @@ DOCUMENTATION = r'''
|
|||
token:
|
||||
description: The Hetzner Cloud API Token.
|
||||
required: false
|
||||
group:
|
||||
description: The group all servers are automatically added to.
|
||||
default: hcloud
|
||||
type: str
|
||||
required: false
|
||||
token_env:
|
||||
description: Environment variable to load the Hetzner Cloud API Token from.
|
||||
default: HCLOUD_TOKEN
|
||||
|
@ -233,8 +238,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
# Server Type
|
||||
if server.server_type is not None:
|
||||
self.inventory.set_variable(server.name, "server_type", to_native(server.server_type.name))
|
||||
else:
|
||||
self.inventory.set_variable(server.name, "server_type", to_native("No server type name found."))
|
||||
|
||||
# Datacenter
|
||||
self.inventory.set_variable(server.name, "datacenter", to_native(server.datacenter.name))
|
||||
|
@ -275,11 +278,11 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
|||
self._get_servers()
|
||||
self._filter_servers()
|
||||
|
||||
# Add a top group 'hcloud'
|
||||
self.inventory.add_group(group="hcloud")
|
||||
# Add a top group
|
||||
self.inventory.add_group(group=self.get_option("group"))
|
||||
|
||||
for server in self.servers:
|
||||
self.inventory.add_host(server.name, group="hcloud")
|
||||
self.inventory.add_host(server.name, group=self.get_option("group"))
|
||||
self._set_server_attributes(server)
|
||||
|
||||
# Use constructed if applicable
|
||||
|
|
Loading…
Reference in a new issue