first version for the collection

Dieser Commit ist enthalten in:
Sebastian Tobie 2023-11-26 16:03:21 +01:00
Ursprung 948c8078b7
Commit 1642135c84
13 geänderte Dateien mit 169 neuen und 10 gelöschten Zeilen

22
CHANGELOG.rst Normale Datei
Datei anzeigen

@ -0,0 +1,22 @@
===================================
stop50.ansible-netcup Release Notes
===================================
.. contents:: Topics
v0.1.0
======
Release Summary
---------------
added inventory module scp
New Plugins
-----------
Inventory
~~~~~~~~~
- sebastian.netcup.scp - Returns Ansible inventory from netcup SCP

Datei anzeigen

@ -1,2 +1,2 @@
# ansible-template
# ansible-netcup

Datei anzeigen

@ -0,0 +1,23 @@
objects:
role: {}
plugins:
become: {}
cache: {}
callback: {}
cliconf: {}
connection: {}
filter: {}
httpapi: {}
inventory:
scp:
description: Returns Ansible inventory from netcup SCP
name: scp
version_added: 0.1.0
lookup: {}
module: {}
netconf: {}
shell: {}
strategy: {}
test: {}
vars: {}
version: 0.1.0

13
changelogs/changelog.yaml Normale Datei
Datei anzeigen

@ -0,0 +1,13 @@
ancestor: null
releases:
0.1.0:
changes:
release_summary: added inventory module scp
fragments:
- scp-added.yml
plugins:
inventory:
- description: Returns Ansible inventory from netcup SCP
name: scp
namespace: null
release_date: '2023-11-26'

Datei anzeigen

@ -3,7 +3,7 @@ changelog_filename_version_depth: 0
changes_file: changelog.yaml
changes_format: combined
ignore_other_fragment_extensions: true
keep_fragments: false
keep_fragments: true
mention_ancestor: true
new_plugins_after_name: removed_features
notesdir: fragments
@ -27,6 +27,7 @@ sections:
- Bugfixes
- - known_issues
- Known Issues
title: stop50.ansible-template
title: stop50.ansible-netcup
trivial_section_name: trivial
use_fqcn: true
always_refresh: full

Datei anzeigen

@ -0,0 +1,2 @@
---
release_summary: added inventory module scp

Datei anzeigen

@ -1,17 +1,17 @@
---
namespace: stop50
name: ansible-template
namespace: sebastian
name: netcup
version: 0.1.0
readme: README.md
authors:
- Sebastian Tobie
description: ''
description: 'netcup specific modules'
license_file: 'LICENSE'
tags: []
dependencies: {}
repository: http://gitea.sebastian-tobie.de/sebastian/ansible-template.git
repository: http://gitea.sebastian-tobie.de/ansible/ansible-netcup.git
documentation:
issues: http://gitea.sebastian-tobie.de/sebastian/ansible-template/issues
issues: http://gitea.sebastian-tobie.de/ansible/ansible-netcup/issues
build_ignore: []

4
inventory.yml Normale Datei
Datei anzeigen

@ -0,0 +1,4 @@
---
plugin: sebastian.netcup.scp
userid:
password:

7
nmap.yml Normale Datei
Datei anzeigen

@ -0,0 +1,7 @@
# inventory.config file in YAML format
plugin: community.general.nmap
strict: false
address: 192.168.170.0/30
ports: true
ipv6: false
port: 22,80,443,445

6
playbook.yml Normale Datei
Datei anzeigen

@ -0,0 +1,6 @@
---
- name: Ping
hosts: all
tasks:
- name: Ping
ansible.builtin.ping: {}

Datei anzeigen

@ -1 +0,0 @@
# ansible-template

81
plugins/inventory/scp.py Normale Datei
Datei anzeigen

@ -0,0 +1,81 @@
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.inventory.data import InventoryData
from ansible.parsing.dataloader import DataLoader
from xmlrpc.client import ServerProxy
from zeep import Client, Settings
from ansible.utils.display import Display
display = Display()
class InventoryModule(BaseInventoryPlugin):
NAME = "sebastian.netcup.scp"
loader: DataLoader
inventory: InventoryData
plugin: str
args: dict[str, str]
def parse(self, inventory: InventoryData, loader: DataLoader, path: str, cache=True):
super(InventoryModule, self).parse(inventory, loader, path, cache)
try:
self.config = self._read_config_data(path)
except Exception as e:
raise e
return
self.plugin = self.config["plugin"]
self.args = dict(loginName=str(self.config["userid"]), password=str(self.config["password"]))
client = Client("https://www.servercontrolpanel.de/SCP/WSEndUser?wsdl", settings=Settings(force_https=True))
self.service = client.service
inventory.add_group("netcup")
inventory.add_group("netcup_online")
inventory.add_group("netcup_offline")
inventory.add_child("netcup", "netcup_online")
inventory.add_child("netcup", "netcup_offline")
for hostname in self.service.getVServers(**self.args):
serverinfo = self.service.getVServerInformation(vservername=hostname, **self.args)
nickname = serverinfo["vServerNickname"] or serverinfo["vServerName"]
group = "netcup_online"
if serverinfo["status"] != "online":
group = "netcup_offline"
if inventory.get_host(nickname) is None:
inventory.add_host(nickname, group)
else:
inventory.add_child(group, nickname)
interfaces = []
for interface in serverinfo["serverInterfaces"]:
interfaces.append(
dict(
driver=interface["driver"],
id=interface["id"],
ipv4=interface["ipv4IP"],
ipv6=interface["ipv6IP"],
mac=interface["mac"],
)
)
inventory.set_variable(nickname, "interfaces", interfaces)
inventory.set_variable(nickname, "memory", serverinfo["memory"])
inventory.set_variable(nickname, "name", serverinfo["vServerName"])
inventory.set_variable(nickname, "cores", serverinfo["cpuCores"])
inventory.set_variable(nickname, "up", serverinfo["status"] == "online")
DOCUMENTATION = r'''
name: sebastian.netcup.scp
plugin_type: inventory
short_description: Returns Ansible inventory from netcup SCP
description: Returns Ansible inventory from netcup SCP
version_added: 0.1.0
options:
plugin:
description: Name of the plugin
required: true
choices: ['scp', "sebastian.netcup.scp"]
userid:
description: userid for logging into SCP
required: true
password:
description:
- API password to authenticate againt the api.
- This is different from you SCP password and must be set indipendently from the SCP password
required: true
'''

Datei anzeigen

@ -1 +1,2 @@
ansible-module>0.1.3
ansible-module>=0.1.3
zeep