From c396f6c628ae6ec3fe655bc49630ad06784924f6 Mon Sep 17 00:00:00 2001 From: Sebastian Tobie Date: Sun, 10 Dec 2023 22:53:35 +0100 Subject: [PATCH] added additional_info parameter --- CHANGELOG.rst | 13 +++++++++++++ changelogs/.plugin-cache.yaml | 2 +- changelogs/changelog.yaml | 9 +++++++++ changelogs/fragments/scp-additional_info.yml | 4 ++++ galaxy.yml | 2 +- plugins/inventory/scp.py | 17 +++++++++++++++-- 6 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/scp-additional_info.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 249c6af..a66754d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,19 @@ stop50.ansible-netcup Release Notes .. contents:: Topics +v0.1.2 +====== + +Release Summary +--------------- + +added additional_info parameter + +Minor Changes +------------- + +- added additional_info to the config. this allows addtional data to be added to the inventory + v0.1.1 ====== diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml index b3f1a79..39fa354 100644 --- a/changelogs/.plugin-cache.yaml +++ b/changelogs/.plugin-cache.yaml @@ -20,4 +20,4 @@ plugins: strategy: {} test: {} vars: {} -version: 0.1.1 +version: 0.1.2 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index bf694a2..f457345 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -18,3 +18,12 @@ releases: fragments: - scp-hostname.yml release_date: '2023-12-10' + 0.1.2: + changes: + minor_changes: + - added additional_info to the config. this allows addtional data to be added + to the inventory + release_summary: added additional_info parameter + fragments: + - scp-additional_info.yml + release_date: '2023-12-10' diff --git a/changelogs/fragments/scp-additional_info.yml b/changelogs/fragments/scp-additional_info.yml new file mode 100644 index 0000000..b099a7f --- /dev/null +++ b/changelogs/fragments/scp-additional_info.yml @@ -0,0 +1,4 @@ +--- +release_summary: added additional_info parameter +minor_changes: + - added additional_info to the config. this allows addtional data to be added to the inventory diff --git a/galaxy.yml b/galaxy.yml index 4810d44..382ca1c 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: ansible name: netcup -version: 0.1.1 +version: 0.1.2 readme: README.md authors: - Sebastian Tobie diff --git a/plugins/inventory/scp.py b/plugins/inventory/scp.py index c1c5038..e97d82a 100644 --- a/plugins/inventory/scp.py +++ b/plugins/inventory/scp.py @@ -32,9 +32,11 @@ class InventoryModule(BaseInventoryPlugin): inventory.add_group("netcup_offline") inventory.add_child("netcup", "netcup_online") inventory.add_child("netcup", "netcup_offline") + additional = self.config.get("additional_info", dict()) for hostname in self.service.getVServers(**self.args): serverinfo = self.service.getVServerInformation(vservername=hostname, **self.args) nickname = serverinfo["vServerNickname"] or serverinfo["vServerName"] + ai = additional.get(nickname, dict()) group = "netcup_online" if serverinfo["status"] != "online": group = "netcup_offline" @@ -43,14 +45,17 @@ class InventoryModule(BaseInventoryPlugin): else: inventory.add_child(group, nickname) interfaces = dict() + ai_interfaces = ai.pop("interfaces", dict()) for interface in serverinfo["serverInterfaces"]: - interfaces[interface["mac"]] = dict( + interfaces[interface["mac"]] = dict() + interfaces[interface["mac"]].update( driver=interface["driver"], id=interface["id"], ipv4=interface["ipv4IP"], ipv6=interface["ipv6IP"], mac=interface["mac"], ) + interfaces[interface["mac"]].update(ai_interfaces.pop(interface["mac"], dict())) if len(interface["ipv4IP"]) > 0: ansible_host = interface["ipv4IP"][0] inventory.set_variable(nickname, "interfaces", interfaces) @@ -58,7 +63,9 @@ class InventoryModule(BaseInventoryPlugin): inventory.set_variable(nickname, "name", serverinfo["vServerName"]) inventory.set_variable(nickname, "cores", serverinfo["cpuCores"]) inventory.set_variable(nickname, "up", serverinfo["status"] == "online") - if self.config.get("nickname_is_hostname", False): + if ai.get("ansible_host", False): + ansible_host = ai.pop("ansible_host") + elif self.config.get("nickname_is_hostname", False): ansible_host = nickname inventory.set_variable(nickname, "ansible_host", ansible_host) @@ -88,4 +95,10 @@ DOCUMENTATION = """ type: bool required: false default: false + additional_info: + version_added: 0.1.2 + description: + required: false + default: {} + type: dict """