From b8ec3a2c27de7eb78575b2c0216f4be986ee5364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Thu, 26 Nov 2020 11:51:47 +0100 Subject: [PATCH 1/4] Add handling of api invisible parameters As we need to handle parameters that doesn't pass through to api we need a parameter for that in parameter specs. We decided to use `api_invisible` for that purpose. The method `_auto_resolve_entities` will sort out these parameters/keys from `desired_entity`. --- plugins/module_utils/phpipam_helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/module_utils/phpipam_helper.py b/plugins/module_utils/phpipam_helper.py index 135b372..89c37a4 100644 --- a/plugins/module_utils/phpipam_helper.py +++ b/plugins/module_utils/phpipam_helper.py @@ -246,7 +246,8 @@ def _auto_resolve_entities(self): need to be resolved and the id of a resolved entity. On that way we also convert boolean into int as the api needed this type. """ - if key in self.phpipam_params: + + if key in self.phpipam_params and not spec.get('api_invisible', False): updated_key = spec.get('phpipam_name', key) @@ -275,6 +276,7 @@ def _phpipam_spec_helper(self, spec): argument_spec = {} _PHPIPAM_SPEC_KEYS = { + 'api_invisible', 'controller', 'flatten', 'phpipam_name', @@ -283,6 +285,7 @@ def _phpipam_spec_helper(self, spec): 'separator', } _VALUE_SPEC_KEYS = { + 'api_invisible', 'controller', 'flatten', 'phpipam_name', From b1ee9bc2a8bb1173ce95d8ad1f5924be00f5ef15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Thu, 26 Nov 2020 11:55:11 +0100 Subject: [PATCH 2/4] Add parameter section to find correct subnet As a subnet can exists in more than one section at all we also need to provide section for an address. This parameter is `api_invisible`, because the phpIPAM api doesn't know anything about this parameter. This will fix #41. --- plugins/modules/address.py | 6 ++++++ tests/test_playbooks/tasks/address.yml | 1 + tests/test_playbooks/vars/address.yml | 1 + 3 files changed, 8 insertions(+) diff --git a/plugins/modules/address.py b/plugins/modules/address.py index 75c8fbc..86efa27 100644 --- a/plugins/modules/address.py +++ b/plugins/modules/address.py @@ -33,6 +33,11 @@ description: subnet address belongs to type: str required: true + section: + description: name of the section the given subnet belongs to + version_added: 1.4.0 + typ: str + required: true ipaddress: description: IP address to hanle type: str @@ -130,6 +135,7 @@ def main(): module = PhpipamAddressModule( phpipam_spec=dict( subnet=dict(type='entity', controller='subnets', required=True, phpipam_name='subnetId'), + section=dict(type='str', api_invisible=True, required=True), ipaddress=dict(type='str', required=True, aliases=['ip', 'address'], phpipam_name='ip'), is_gateway=dict(type='bool', phpipam_name='is_gateway'), description=dict(type='str'), diff --git a/tests/test_playbooks/tasks/address.yml b/tests/test_playbooks/tasks/address.yml index a2705b3..863a2d3 100644 --- a/tests/test_playbooks/tasks/address.yml +++ b/tests/test_playbooks/tasks/address.yml @@ -6,6 +6,7 @@ username: "{{ phpipam_username }}" password: "{{ phpipam_password }}" subnet: "{{ address.subnet }}" + section: "{{ address.section }}" ipaddress: "{{ address.ipaddress }}" is_gateway: "{{ address.is_gateway | default(omit) }}" description: "{{ address.description | default(omit) }}" diff --git a/tests/test_playbooks/vars/address.yml b/tests/test_playbooks/vars/address.yml index d81c228..b23ffe3 100644 --- a/tests/test_playbooks/vars/address.yml +++ b/tests/test_playbooks/vars/address.yml @@ -2,4 +2,5 @@ base_address_data: ipaddress: 172.16.0.1 subnet: 172.16.0.0/24 + section: Customers is_gateway: yes From 91ca58f6c5d7e1dcbd3d838f292eb5f88a329afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Thu, 26 Nov 2020 12:01:49 +0100 Subject: [PATCH 3/4] add changelog for #41 --- changelogs/fragments/missing_section_for_addresses.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/missing_section_for_addresses.yml diff --git a/changelogs/fragments/missing_section_for_addresses.yml b/changelogs/fragments/missing_section_for_addresses.yml new file mode 100644 index 0000000..5591cbd --- /dev/null +++ b/changelogs/fragments/missing_section_for_addresses.yml @@ -0,0 +1,2 @@ +bugfixes: + - fix `KeyError 'section'` bug (https://github.com/codeaffen/phpipam-ansible-modules/issues/41) From 992660a5af799cb96a0b22b024e83965dfd0b07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Thu, 26 Nov 2020 12:21:20 +0100 Subject: [PATCH 4/4] prepare release 1.3.1 --- .bumpversion.cfg | 2 +- CHANGELOG.rst | 8 + changelogs/changelog.yaml | 7 + .../missing_section_for_addresses.yml | 2 - docs/plugins/address_module.rst | 453 +----------------- docs/plugins/index.rst | 2 +- galaxy.yml | 2 +- 7 files changed, 30 insertions(+), 446 deletions(-) delete mode 100644 changelogs/fragments/missing_section_for_addresses.yml diff --git a/.bumpversion.cfg b/.bumpversion.cfg index bcad484..a3dd1de 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,6 +1,6 @@ [bumpversion] commit = False tag = False -current_version = 1.3.0 +current_version = 1.3.1 [bumpversion:file:galaxy.yml] diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aff2349..7a35144 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,14 @@ codeaffen.phpipam Release Notes .. contents:: Topics +v1.3.1 +====== + +Bugfixes +-------- + +- fix `KeyError 'section'` bug (https://github.com/codeaffen/phpipam-ansible-modules/issues/41) + v1.3.0 ====== diff --git a/changelogs/changelog.yaml b/changelogs/changelog.yaml index 4e22b46..a8cbad0 100644 --- a/changelogs/changelog.yaml +++ b/changelogs/changelog.yaml @@ -73,3 +73,10 @@ releases: fragments: - same_subnet_in_different_sections.yml release_date: '2020-11-23' + 1.3.1: + changes: + bugfixes: + - fix `KeyError 'section'` bug (https://github.com/codeaffen/phpipam-ansible-modules/issues/41) + fragments: + - missing_section_for_addresses.yml + release_date: '2020-11-26' diff --git a/changelogs/fragments/missing_section_for_addresses.yml b/changelogs/fragments/missing_section_for_addresses.yml deleted file mode 100644 index 5591cbd..0000000 --- a/changelogs/fragments/missing_section_for_addresses.yml +++ /dev/null @@ -1,2 +0,0 @@ -bugfixes: - - fix `KeyError 'section'` bug (https://github.com/codeaffen/phpipam-ansible-modules/issues/41) diff --git a/docs/plugins/address_module.rst b/docs/plugins/address_module.rst index 2a5849c..2cbb9c6 100644 --- a/docs/plugins/address_module.rst +++ b/docs/plugins/address_module.rst @@ -1,457 +1,28 @@ -.. Document meta +.. Document meta section :orphan: +.. Document body + .. Anchors .. _ansible_collections.codeaffen.phpipam.address_module: -.. Anchors: short name for ansible.builtin - -.. Anchors: aliases - - - .. Title -codeaffen.phpipam.address -- Manage addresses -+++++++++++++++++++++++++++++++++++++++++++++ - -.. Collection note - -.. note:: - This plugin is part of the `codeaffen.phpipam collection `_. - - To install it use: :code:`ansible-galaxy collection install codeaffen.phpipam`. - - To use it in a playbook, specify: :code:`codeaffen.phpipam.address`. - -.. version_added - -.. versionadded:: 0.2.0 of codeaffen.phpipam - -.. contents:: - :local: - :depth: 1 - -.. Deprecated - - -Synopsis --------- - -.. Description - -- create, update and delete addresses - - -.. Aliases - - -.. Requirements - -Requirements ------------- -The below requirements are needed on the host that executes this module. - -- inflection -- ipaddress -- phpypam>=1.0.0 - - -.. Options - -Parameters ----------- - -.. raw:: html - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ParameterChoices/DefaultsComments
-
- app_id - -
- string -
-
- Default:
"ansible"
-
-
API app name
-
-
- description - -
- string -
-
- -
Address description
-
-
- device - -
- string -
-
- -
Device address belongs to
-
-
- exclude_ping - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes
  • -
-
-
Exclude this address from status update scans
-
-
- hostname - -
- string -
-
- -
Address hostname
-
-
- ignore_ptr - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Controls if PTR should not be created
-
-
- ipaddress - -
- string - / required
-
- -
IP address to hanle
-

aliases: ip, address
-
-
- is_gateway - -
- boolean -
-
-
    Choices: -
  • no ←
  • -
  • yes
  • -
-
-
Defines if address is presented as gateway
-
-
- mac_address - -
- string -
-
- -
Mac address
-

aliases: mac
-
-
- note - -
- string -
-
- -
Note
-
-
- owner - -
- string -
-
- -
Address owner
-
-
- password - -
- string - / required
-
- -
Password of the user to access phpIPAM server
-
-
- port - -
- string -
-
- -
Port
-
-
- ptr - -
- string -
-
- -
DNS PTR record
-
-
- server_url - -
- string - / required
-
- -
URL of the phpIPAM server
-
-
- state - -
- string -
-
-
    Choices: -
  • present ←
  • -
  • absent
  • -
-
-
State of the entity
-
-
- subnet - -
- string - / required
-
- -
subnet address belongs to
-
-
- tag - -
- string -
-
- -
IP tag (online, offline, ...)
-
-
- username - -
- string - / required
-
- -
Username to access phpIPAM server
-
-
- validate_certs - -
- boolean -
-
-
    Choices: -
  • no
  • -
  • yes ←
  • -
-
-
Is the TLS certificate of the phpIPAM server verified or not.
-
-
- -.. Notes - - -.. Seealso - - -.. Examples - -Examples --------- - -.. code-block:: yaml+jinja - - - - name: "Reserve a IP address" - codeaffen.phpipam.section: - username: "admin" - password: "s3cr3t" - server_url: "https://ipam.example.com" - address: "192.0.2.1" - description: "Default router of sunet" - subnet: "192.0.2.0/24" - is_gateway: yes - state: present - - - name: "Remove address reservation" - codeaffen.phpipam.section: - username: "admin" - password: "s3cr3t" - server_url: "https://ipam.example.com" - address: "192.0.2.1" - subnet: "192.0.2.0/24" - state: absent - - - - -.. Facts - - -.. Return values - - -.. Status (Presently only deprecated) - +codeaffen.phpipam.address ++++++++++++++++++++++++++ -.. Authors -Authors -~~~~~~~ +The documentation for the module plugin, codeaffen.phpipam.address, was malformed. -- Christian Meißner (@cmeissner) +The errors were: +* :: + 1 validation error for ModuleDocSchema + doc -> options -> section -> typ + extra fields not permitted (type=value_error.extra) -.. Parsing errors +File a bug with the `codeaffen.phpipam collection `_ in order to have it corrected. \ No newline at end of file diff --git a/docs/plugins/index.rst b/docs/plugins/index.rst index 2c584a1..c360032 100644 --- a/docs/plugins/index.rst +++ b/docs/plugins/index.rst @@ -14,7 +14,7 @@ These are the plugins in the codeaffen.phpipam collection Modules ------- -* :ref:`address ` -- Manage addresses +* :ref:`address ` -- * :ref:`device ` -- Manage devices * :ref:`device_type ` -- Manage device types * :ref:`domain ` -- Manage L2 routing domains diff --git a/galaxy.yml b/galaxy.yml index 96ddb5e..930271b 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -3,7 +3,7 @@ name: "phpipam" description: Ansible Modules to manage phpIPAM installations authors: - "Christian Meißner " -version: "1.3.0" +version: "1.3.1" license: - "GPL-3.0-or-later" tags: