added additional_info parameter

Dieser Commit ist enthalten in:
Sebastian Tobie 2023-12-10 22:53:35 +01:00
Ursprung 026f1240ee
Commit c396f6c628
6 geänderte Dateien mit 43 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -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
======

Datei anzeigen

@ -20,4 +20,4 @@ plugins:
strategy: {}
test: {}
vars: {}
version: 0.1.1
version: 0.1.2

Datei anzeigen

@ -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'

Datei anzeigen

@ -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

Datei anzeigen

@ -1,7 +1,7 @@
---
namespace: ansible
name: netcup
version: 0.1.1
version: 0.1.2
readme: README.md
authors:
- Sebastian Tobie

Datei anzeigen

@ -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
"""