diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..c18ed46 --- /dev/null +++ b/CHANGELOG.rst @@ -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 diff --git a/README.md b/README.md index ea48422..ca9f8dc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# ansible-template +# ansible-netcup diff --git a/changelogs/.plugin-cache.yaml b/changelogs/.plugin-cache.yaml new file mode 100644 index 0000000..da3854e --- /dev/null +++ b/changelogs/.plugin-cache.yaml @@ -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 diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml new file mode 100644 index 0000000..842071b --- /dev/null +++ b/changelogs/changelog.yaml @@ -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' diff --git a/changelogs/config.yaml b/changelogs/config.yaml index 4da4a85..92e2a06 100644 --- a/changelogs/config.yaml +++ b/changelogs/config.yaml @@ -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 diff --git a/changelogs/fragments/scp-added.yml b/changelogs/fragments/scp-added.yml new file mode 100644 index 0000000..e5aee9d --- /dev/null +++ b/changelogs/fragments/scp-added.yml @@ -0,0 +1,2 @@ +--- +release_summary: added inventory module scp diff --git a/galaxy.yml b/galaxy.yml index d80f5a0..d433243 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -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: [] diff --git a/inventory.yml b/inventory.yml new file mode 100644 index 0000000..71b9874 --- /dev/null +++ b/inventory.yml @@ -0,0 +1,4 @@ +--- +plugin: sebastian.netcup.scp +userid: +password: diff --git a/nmap.yml b/nmap.yml new file mode 100644 index 0000000..4949ec7 --- /dev/null +++ b/nmap.yml @@ -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 diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..7b87067 --- /dev/null +++ b/playbook.yml @@ -0,0 +1,6 @@ +--- +- name: Ping + hosts: all + tasks: + - name: Ping + ansible.builtin.ping: {} diff --git a/plugins/README.md b/plugins/README.md deleted file mode 100644 index 5cbe34c..0000000 --- a/plugins/README.md +++ /dev/null @@ -1 +0,0 @@ -# ansible-template diff --git a/plugins/inventory/scp.py b/plugins/inventory/scp.py new file mode 100644 index 0000000..ce12e07 --- /dev/null +++ b/plugins/inventory/scp.py @@ -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 +''' diff --git a/requirements.txt b/requirements.txt index 151f0db..d49df48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -ansible-module>0.1.3 +ansible-module>=0.1.3 +zeep