Commits vergleichen

..

2 Commits

4 geänderte Dateien mit 27 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,2 @@
---
release_summary: added nickname_is_hostname config to let the nickname be the hostname of the host

Datei anzeigen

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

Datei anzeigen

@ -1,4 +1,5 @@
--- ---
plugin: sebastian.netcup.scp plugin: ansible.netcup.scp
userid: userid:
password: password:
nickname_is_hostname: false

Datei anzeigen

@ -10,7 +10,7 @@ display = Display()
class InventoryModule(BaseInventoryPlugin): class InventoryModule(BaseInventoryPlugin):
NAME = "sebastian.netcup.scp" NAME = "ansible.netcup.scp"
loader: DataLoader loader: DataLoader
inventory: InventoryData inventory: InventoryData
plugin: str plugin: str
@ -42,26 +42,29 @@ class InventoryModule(BaseInventoryPlugin):
inventory.add_host(nickname, group) inventory.add_host(nickname, group)
else: else:
inventory.add_child(group, nickname) inventory.add_child(group, nickname)
interfaces = [] interfaces = dict()
for interface in serverinfo["serverInterfaces"]: for interface in serverinfo["serverInterfaces"]:
interfaces.append( interfaces[interface["mac"]] = dict(
dict(
driver=interface["driver"], driver=interface["driver"],
id=interface["id"], id=interface["id"],
ipv4=interface["ipv4IP"], ipv4=interface["ipv4IP"],
ipv6=interface["ipv6IP"], ipv6=interface["ipv6IP"],
mac=interface["mac"], mac=interface["mac"],
) )
) if len(interface["ipv4IP"]) > 0:
ansible_host = interface["ipv4IP"][0]
inventory.set_variable(nickname, "interfaces", interfaces) inventory.set_variable(nickname, "interfaces", interfaces)
inventory.set_variable(nickname, "memory", serverinfo["memory"]) inventory.set_variable(nickname, "memory", serverinfo["memory"])
inventory.set_variable(nickname, "name", serverinfo["vServerName"]) inventory.set_variable(nickname, "name", serverinfo["vServerName"])
inventory.set_variable(nickname, "cores", serverinfo["cpuCores"]) inventory.set_variable(nickname, "cores", serverinfo["cpuCores"])
inventory.set_variable(nickname, "up", serverinfo["status"] == "online") inventory.set_variable(nickname, "up", serverinfo["status"] == "online")
if self.config.get("nickname_is_hostname", False):
ansible_host = nickname
inventory.set_variable(nickname, "ansible_host", ansible_host)
DOCUMENTATION = r""" DOCUMENTATION = """
name: sebastian.netcup.scp name: ansible.netcup.scp
plugin_type: inventory plugin_type: inventory
short_description: Returns Ansible inventory from netcup SCP short_description: Returns Ansible inventory from netcup SCP
description: Returns Ansible inventory from netcup SCP description: Returns Ansible inventory from netcup SCP
@ -70,7 +73,7 @@ DOCUMENTATION = r"""
plugin: plugin:
description: Name of the plugin description: Name of the plugin
required: true required: true
choices: ['scp', "sebastian.netcup.scp"] choices: ['scp', "ansible.netcup.scp"]
userid: userid:
description: userid for logging into SCP description: userid for logging into SCP
required: true required: true
@ -79,4 +82,10 @@ DOCUMENTATION = r"""
- API password to authenticate againt the api. - API password to authenticate againt the api.
- This is different from you SCP password and must be set indipendently from the SCP password - This is different from you SCP password and must be set indipendently from the SCP password
required: true required: true
nickname_is_hostname:
version_added: 0.1.1
description: use the nickname as hostname
type: bool
required: false
default: false
""" """