GithubHelp home page GithubHelp logo

codeaffen / phpipam-ansible-modules Goto Github PK

View Code? Open in Web Editor NEW
21.0 4.0 10.0 317 KB

Ansible Modules to manage phpIPAM installations

Home Page: https://codeaffen.org/projects/phpipam-ansible-modules

License: GNU General Public License v3.0

Python 94.57% Makefile 4.23% Shell 1.19%
ansible-modules phpipam ansible phpipam-api phpipam-ansible-modules hacktoberfest

phpipam-ansible-modules's Introduction

phpIPAM Ansible Modules

Dynamic JSON Badge Codacy Badge Documentation Status

This collection provides modules to manage entities in a phpIPAM. This is neither a collection of roles nor playbooks. It provides modules to write your own roles and/or playbooks.

We get a lot of inspiration from foreman-ansible-modules for our modules.

Installation

The collection is available via Ansible Galaxy. So you can run

ansible-galaxy collection install codeaffen.phpipam

Alternatively you can build and install the collection from source.

make dist
ansible-galaxy collection install codeaffen-phpipam-<version>.tar.gz

Documentation

readthedocs.io

Current documentation can be found on readthedocs.io.

ansible-doc

If you have installed the collection you can facilitate ansible-doc to display documentation for a given module.

ansible-doc codeaffen.phpipam.section

repository folder

A last option to read the docs is the docs folder in this repository.

Dependencies

The following dependencies have to be fulfiled by the Ansible controller.

  • colour
  • geopy
  • inflection
  • ipaddress
  • phpypam>=1.0.0

Need help?

If you’ve found any issues in this release please head over to github and open a bug so we can take a look.

phpipam-ansible-modules's People

Contributors

cmeissner avatar flatkey avatar gmzabos avatar kmonticolo avatar lush avatar mario-f avatar pyup-bot avatar scottatron avatar summacumwilly avatar tanducmai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

phpipam-ansible-modules's Issues

`validate_certs` is not used for api connection

Describe the bug

After implementing validate_certs the parameter is not used for API connection

To Reproduce

Steps to reproduce the behavior:

  • connect to a phpIPAM API with self-signed certificate
  • see ssl error in ansible output

Expected behavior

Connection should be established to API with self-signed certificates.

Versions:

  • Ansible: 2.9.15
  • phpipam-ansible-modules: 1.1.0
  • phpypam: 1.0.0

add facility to setup local phpipam environment

Is your feature request related to a problem? Please describe.

To give all developers and contributors the ability to easily set up a local phpipam environment with database and phpipam.

Describe the solution you'd like

  • The solution should use docker-compose to spin up mariadb and phpipam-www container.
  • Database needs to be created with current schema
  • API needs to be enabled
  • API application needs to be created

Problem with option show_supernets_only

Hi!

When using option "show_supernet_only" i get exception:

phpypam.core.exceptions.PHPyPAMInvalidSyntax: Invalid request key showSupernetsOnly

To Reproduce
Steps to reproduce the behavior:
use option "show_supernet_only" in playbook

Expected behavior
Section created

Versions:

  • Ansible: 2.13
  • phpipam-ansible-modules: 1.6.1
  • phpypam: 1.0.2

Cannot assign vlan to subnet with the subnet module

I have deployed phpIPAM

Installed phpIPAM release: 1.7.0
Database schema version: 1.7 dbversion 41
PHP version: 8.1.2-1ubuntu2.14
MySQL version: 10.6.16-MariaDB-0ubuntu0.22.04.1

I have already configured vlans 1 to 1000 via ansible for the default l2domain

Snippet form the DB:

MariaDB [phpipam]> select * FROM vlanDomains
    -> ;
+----+---------+-------------------+-------------+
| id | name    | description       | permissions |
+----+---------+-------------------+-------------+
|  1 | default | default L2 domain | NULL        |
+----+---------+-------------------+-------------+
1 row in set (0.001 sec)

MariaDB [phpipam]> SELECT * FROM vlans limit 5;
+--------+----------+------+--------+-------------+----------+-------------+
| vlanId | domainId | name | number | description | editDate | customer_id |
+--------+----------+------+--------+-------------+----------+-------------+
|     70 |        1 | 1    |      1 | NULL        | NULL     |        NULL |
|     71 |        1 | 2    |      2 | NULL        | NULL     |        NULL |
|     72 |        1 | 3    |      3 | NULL        | NULL     |        NULL |
|     73 |        1 | 4    |      4 | NULL        | NULL     |        NULL |
|     74 |        1 | 5    |      5 | NULL        | NULL     |        NULL |
+--------+----------+------+--------+-------------+----------+-------------+
5 rows in set (0.001 sec)

When trying to deploy a subnet and assign a vlan to it, I get "Can not resolve 'vlan' to an existing ID"

This is my playbook:

- hosts: localhost
  collections:
    - codeaffen.phpipam
  connection: httpapi
  gather_facts: false
  vars:
   phpipam_server_url: "https://ob-ipam.foo.net"
   phpipam_app_id: "ansible"
  vars_prompt:
    - name: phpipam_username
      prompt: "phpIPAM username"
      private: no
    - name: phpipam_password
      prompt: "phpIPAM password"
      private: yes
  tasks:
  - name: Add subnet
    codeaffen.phpipam.subnet:
      username: "{{ phpipam_username }}"
      password: "{{ phpipam_password }}"
      server_url: "{{ phpipam_server_url }}"
      app_id: "{{ phpipam_app_id }}"
      validate_certs: false
      cidr: "10.32.68.0/24"
      parent: "10.32.64.0/19"
      description: "SHARED-ACCESS"
      vlan: "1"
      routing_domain: "default"
      section: "OB Prod Net"
      state: present

Here is the result of running the playbook

$ ansible-playbook -i localhost  playbooks/phpipamsubnet.py -vvv
ansible-playbook [core 2.13.13]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/eftner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/eftner/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/eftner/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/eftner/.local/bin/ansible-playbook
  python version = 3.8.0 (default, Jan 31 2024, 12:25:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
  jinja version = 3.1.3
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/eftner/infra-ansible/localhost as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /home/eftner/infra-ansible/localhost as it did not pass its verify_file() method
auto declined parsing /home/eftner/infra-ansible/localhost as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /home/eftner/infra-ansible/localhost as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /home/eftner/infra-ansible/localhost as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /home/eftner/infra-ansible/localhost as it did not pass its verify_file() method
[WARNING]: Unable to parse /home/eftner/infra-ansible/localhost as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
redirecting (type: callback) ansible.builtin.debug to ansible.posix.debug
redirecting (type: callback) ansible.builtin.debug to ansible.posix.debug
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: phpipamsubnet.py ***********************************************************************************************************************************************************************************
1 plays in playbooks/phpipamsubnet.py
phpIPAM username: eftner
phpIPAM password:

PLAY [localhost] *********************************************************************************************************************************************************************************************
META: ran handlers

TASK [Add subnet] ********************************************************************************************************************************************************************************************
task path: /home/eftner/infra-ansible/playbooks/phpipamsubnet.py:17
Using module file /home/eftner/.ansible/collections/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py
Pipelining is enabled.
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: eftner
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/env python && sleep 0'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_requests": null,
            "app_id": "ansible",
            "cidr": "10.32.68.0/24",
            "description": "SHARED-ACCESS",
            "discover_subnet": null,
            "dns_records": null,
            "dns_recursive": null,
            "folder": null,
            "is_folder": null,
            "is_full": null,
            "linked_subnet": null,
            "location": null,
            "mask": null,
            "nameserver": null,
            "parent": "10.32.64.0/19",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "permissions": null,
            "ping_subnet": null,
            "routing_domain": "default",
            "scan_agent": null,
            "section": "OB Prod Net",
            "server_url": "https://ob-ipam.foo.net",
            "show_as_name": null,
            "subnet": null,
            "subnet_state": null,
            "threshold": null,
            "username": "eftner",
            "validate_certs": false,
            "vlan": "1",
            "vrf": null
        }
    }
}

MSG:

Can not resolve 'vlan' to an existing ID

PLAY RECAP ***************************************************************************************************************************************************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Versions:

  • Ansible:

    $ ansible --version
    ansible [core 2.13.13]
    config file = /etc/ansible/ansible.cfg
    configured module search path = ['/home/eftner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /home/eftner/.local/lib/python3.8/site-packages/ansible
    ansible collection location = /home/eftner/.ansible/collections:/usr/share/ansible/collections
    executable location = /home/eftner/.local/bin/ansible
    python version = 3.8.0 (default, Jan 31 2024, 12:25:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
    jinja version = 3.1.3
    libyaml = True
  • phpipam-ansible-modules:

    $ ansible-galaxy collection list codeaffen.phpipam
    Collection        Version
    ----------------- -------
    codeaffen.phpipam 1.7.0
  • phpypam:

    $ pip freeze | grep phpypam
    phpypam==1.0.2
  • phpIPAM:

    $ Version from webUI
    1.7.0
  • python version

    $ python -V
    Python 3.8.0
  • list of python libraries:

    $ pip freeze
    certifi==2023.11.17
    charset-normalizer==3.3.2
    idna==3.6
    inflection==0.5.1
    phpypam==1.0.2
    requests==2.31.0
    urllib3==1.26.6

Run into `KeyError: 'section'` error when using `address` module

Describe the bug

When calling address module we run into a KeyError. The module is complaining about section which is not there.

To Reproduce

  • following variable is set:
address:
  ipaddress: 172.16.0.1
  subnet: 172.16.0.0/24
  is_gateway: yes
  • run the following ansible task with -vvv:
- name: "Ensure state of ip address: {{ name }}"
  address:
    server_url: "{{ phpipam_server_url }}"
    app_id: "{{ phpipam_app_id }}"
    username: "{{ phpipam_username }}"
    password: "{{ phpipam_password }}"
    subnet: "{{ address.subnet }}"
    ipaddress: "{{ address.ipaddress }}"
    is_gateway: "{{ address.is_gateway | default(omit) }}"
    description: "{{ address.description | default(omit) }}"
    mac_address: "{{ address.mac_address | default(omit) }}"
    owner: "{{ address.owner | default(omit) }}"
    tag: "{{ address.tag | default(omit) }}"
    ignore_ptr: "{{ address.ignore_ptr | default(omit) }}"
    ptr: "{{ address.ptr | default(omit) }}"
    device: "{{ address.device | default(omit) }}"
    port: "{{ address.port | default(omit) }}"
    note: "{{ address.note | default(omit) }}"
    exclude_ping: "{{ address.exclude_ping | default(omit) }}"
    state: "{{ address.state | default('present') }}"
  • See following error:
  File "/var/folders/dn/t64yh4j91fscbqw3rd2_frt9pq8rlt/T/ansible_address_payload_trd382xu/ansible_address_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/address.py", line 157, in <module>
  File "/var/folders/dn/t64yh4j91fscbqw3rd2_frt9pq8rlt/T/ansible_address_payload_trd382xu/ansible_address_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/address.py", line 153, in main
  File "/var/folders/dn/t64yh4j91fscbqw3rd2_frt9pq8rlt/T/ansible_address_payload_trd382xu/ansible_address_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 505, in run
  File "/var/folders/dn/t64yh4j91fscbqw3rd2_frt9pq8rlt/T/ansible_address_payload_trd382xu/ansible_address_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 254, in _auto_resolve_entities
  File "/var/folders/dn/t64yh4j91fscbqw3rd2_frt9pq8rlt/T/ansible_address_payload_trd382xu/ansible_address_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 214, in _resolve_entity
KeyError: 'section'

Expected behavior

The Address should be managed.

Versions:

  • Ansible: 2.9.15
  • phpipam-ansible-modules: 1.3.0
  • phpypam: 1.0.0

Additional context

This behavior can be observed since v1.3.0 of codeaffen.phpipam

Can't add VLAN to subnet

Describe the bug
Can't set VLAN_ID on subnets

To Reproduce
Steps to reproduce the behavior:

  1. Create a vlan in phpipam
  2. Try to create a subnet using the subnets module and specify that vlan in the creation

Expected behavior
The subnet is created with the vlan,

Versions:

  • Ansible: 2.10.8
  • phpipam-ansible-modules: 1.5.0
  • phpypam: 1.0.2

Additional context

Creating the vlan using ansible

            "vlan": [
                {
                    "customer_id": null,
                    "description": "test",
                    "domainId": "1",
                    "editDate": null,
                    "name": "test",
                    "number": "15",
                    "vlanId": "5"
                }
            ]
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1660646339.1970553-1594591-77023668181494/AnsiballZ_subnet.py", line 102, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1660646339.1970553-1594591-77023668181494/AnsiballZ_subnet.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1660646339.1970553-1594591-77023668181494/AnsiballZ_subnet.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.codeaffen.phpipam.plugins.modules.subnet', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py", line 251, in <module>
  File "/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py", line 247, in main
  File "/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 509, in run
  File "/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 256, in _auto_resolve_entities
TypeError: 'NoneType' object is not subscriptable

----

    "module_stdout": "Traceback (most recent call last):\r\n  File \"/root/.ansible/tmp/ansible-tmp-1660646339.1970553-1594591-77023668181494/AnsiballZ_subnet.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/root/.ansible/tmp/ansible-tmp-1660646339.1970553-1594591-77023668181494/AnsiballZ_subnet.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/root/.ansible/tmp/ansible-tmp-1660646339.1970553-1594591-77023668181494/AnsiballZ_subnet.py\", line 40, in invoke_module\r\n    runpy.run_module(mod_name='ansible_collections.codeaffen.phpipam.plugins.modules.subnet', init_globals=None, run_name='__main__', alter_sys=True)\r\n  File \"/usr/lib/python3.9/runpy.py\", line 210, in run_module\r\n    return _run_module_code(code, init_globals, run_name, mod_spec)\r\n  File \"/usr/lib/python3.9/runpy.py\", line 97, in _run_module_code\r\n    _run_code(code, mod_globals, init_globals,\r\n  File \"/usr/lib/python3.9/runpy.py\", line 87, in _run_code\r\n    exec(code, run_globals)\r\n  File \"/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py\", line 251, in <module>\r\n  File \"/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py\", line 247, in main\r\n  File \"/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 509, in run\r\n  File \"/tmp/ansible_codeaffen.phpipam.subnet_payload_qf3b_313/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 256, in _auto_resolve_entities\r\nTypeError: 'NoneType' object is not subscriptable\r\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1,
    "subnet": {
        "cidr": "192.168.2.0/24",
        "description": "test",
        "location": "test",
        "section": "test",
        "vlan": "15"
    }
}

# Same result with using the vlanId 

    "subnet": {
        "cidr": "192.168.2.0/24",
        "description": "test",
        "location": "test",
        "section": "test",
        "vlan": "5"
    }


Failed to import the required Python library on VM's Python /usr/bin/python

Describe the bug

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'phpypam'

I am using Debian 12 and PIP is not allowed to install packages globally. Before I used pip install phpypam globally and it worked.

Now I have created a venv on the my ipam VM. When running my ansible-playbook from a controller node. I get this message, even though I try to set ansible_python_interpreter.

changing ansible_python_interprer the command 'which python' always returns /usr/bin/python on the ipam VM, instead of the venv python.

The flow of using ansible:

Controller (Uses Venv with ansible installed e.g. ~/git-repo/with-playbook/venv/bin/activate) -> IPAM VM ( Has /opt/docker_venv/bin/python that I set with the ansible_python_interpreter)

To Reproduce

I tried to change the python_interpreter to use different python version on the ipam VM. NB! the interpeter venv path is the one in the VM not in the controller. I am not sure how it works. which version of python it uses?

image

Expected behavior

Use correct venv.

Versions:

  • Ansible:
  • phpipam-ansible-modules:
  • phpypam:
  • phpIPAM:

Additional context
Add any other context about the problem here.

Creating same subnet in different sections isn't possible

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

Expected behavior
A clear and concise description of what you expected to happen.

Versions:

  • Ansible:
  • phpipam-ansible-modules
  • phpypam

Additional context
Add any other context about the problem here.

There is no `validate_certs` parameter in modules

Describe the bug

Currently there is no validate_certs parameter on any of the provides ansible modules. So we can't use the modules with unvalid (self signed) certificates.

To Reproduce

  1. configure sth like this:
- name: "working on section '{{ section.name }}'"
  codeaffen.phpipam.section:
    username: "{{ phpipam_admin }}"
    password: "{{ phpipam_admin_password }}"
    server_url: "https://ipam.example.com"
    validate_certs: "{{ validate_certs }}"
    name: "{{ section.name }}"
    description: "{{ section.description }}"
    state: present
  1. run ansible and see following error:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (codeaffen.phpipam.section) module: validate_certs Supported parameters include: app_id, description, dns_resolver, list_order, name, parent, password, permissions, server_url, show_supernets_only, show_vlan, show_vrf, state, strict_mode, subnet_ordering, username"}
```
**Expected behavior**

Ansible task should run withou any errors.

**Versions:**

- Ansible: 2.9.x
- phpipam-ansible-modules: 1.0.0
- phpypam: 1.0.0

**Additional context**

`hostname` parameter missing in task for address test case

Describe the bug
in tests/test_playbooks/tasks/address.yml there is no line to specify to set the hostname

To Reproduce
use the test_playbook to create an ip record and set the hostname
notice in phpipam that the record is created, but the hostname not created

Expected behavior
expected hostname field to be set also

Versions:

  • Ansible: irrelevant
  • phpipam-ansible-modules: irrelevant
  • phpypam: irrelevant

Additional context
the missing line is
hostname: "{{ address.hostname }}"
after adding this line, the hostname gets set correctly.

Subnet boolean values not working

Describe the bug
Certain boolean values of the subnet playbook is providing an error.

To Reproduce
Change value of 'ping_subnet', 'discover_subnet' or 'is_folder' to 'true' or 'yes'.

--- base_subnet_data: cidr: 10.0.0.0/24 section: "Private IPv4" ping_subnet: yes discover_subnet: yes is_folder: yes

Expected behavior
Expect the playbook to recognize the value is set to yes and have the subnet be created successfully with the values shown on the GUI.

Versions:

  • Ansible: 2.13.5
  • phpipam-ansible-modules: 1.6.0
  • phpypam: 1.0.2

Additional context
Full error log attached
ansible_error.txt

Add parameter for l2domain to `subnet` module

Is your feature request related to a problem? Please describe.

Another thing to consider is that when adding a subnet to a VLAN then in the GUI it shows the different l2 domains, but when using the ansible modules, currently the l2 domain can not be specified and it will choose randomly, which l2 domain it picks.

Originally posted by @TafkaMax in #84 (comment)

Describe the solution you'd like

To solve this task it becomes necessary to add a domain parameter to our subnet module. This parameter needs to be mandatory after implementing #84. It should also defaulted to default as in vlan module.

Describe alternatives you've considered

For the while we don't have such a parameter we provide default l2domain as default for resolving vlans. In that case multi domain vlans are not supported.

Additional context

Simply adding the parameter with default should be enough but we need to be aware that this parameter should never presented to API as it is not supported.

$ rg api_invisible
plugins/modules/location.py
134:            resolv_location=dict(type='bool', required=False, default=False, api_invisible=True),

plugins/modules/address.py
140:            section=dict(type='str', api_invisible=True, required=True),

plugins/module_utils/phpipam_helper.py
276:            if key in self.phpipam_params and not spec.get('api_invisible', False):
305:            'api_invisible',
314:            'api_invisible',

Inventory module?

Is your feature request related to a problem? Please describe.
Phpipam seems to be one of those source of truth, that is ignored to a huge degree, as an inventory source. Yes, the API is useful and it's easy to make a playbook that calls and creates an inventory file. However for a lot of folks, like me, whose Python skills are quite horrible.. finding a plugin or a module to use for inventory purposes has ended in empty hands.

Describe the solution you'd like
You guys already have a nice, well-rounded Collection. Including an inventory plugin or module would be icing on the cake.

Describe alternatives you've considered
So far I've tried a playbook/template that makes an API call with various filters, to create an inventory.yaml file using a template. Also testing the ansible.builtin.script module to perform the same basic thing, except the yml calls a python script (translated from the playbook) to perform the same functions. Inventory scripts, while still technically supported, plugins are recommended by the Community and RH.

Additional context
If this functionality already exists in some form please correct me. I was not able to find anything related to this in the existing documentation.

folder creation is not idempotent

Describe the bug
When using option "is_folder" for creating folder, restart this play create the same folder in the same section

To Reproduce
create play:

  • name: Create folder
    subnet:
    bla-bla-bla:
    is_folder: true

Expected behavior
Folder is created, but next run play will create new the same folder

Versions:

  • Ansible: 2.13
  • phpipam-ansible-modules: 1.6.1
  • phpypam: 1.0.2

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Module failure for phpipam v1.6

Describe the bug
I have deployed phpIPAM IP address management [v1.6.0] dbversion 39 using php v8.2. When running a basic playbook to just add a subnet, i get an error as per below:

- name: Subnet module tests
  hosts: localhost
  gather_facts: false
  tasks:
  - name: "Create a subnet"
    codeaffen.phpipam.subnet:
      username: "admin"
      password: "mypassword"
      server_url: "http://localhost"
      cidr: "192.0.2.128/26"
      validate_certs: false
      app_id: "ansible"
      section: "Customers"
      state: present
The full traceback is:
Traceback (most recent call last):
  File "/Users/myuser/.ansible/tmp/ansible-tmp-1701953976.2923598-86153-236914147207910/AnsiballZ_subnet.py", line 107, in <module>
    _ansiballz_main()
  File "/Users/myuser/.ansible/tmp/ansible-tmp-1701953976.2923598-86153-236914147207910/AnsiballZ_subnet.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/myuser/.ansible/tmp/ansible-tmp-1701953976.2923598-86153-236914147207910/AnsiballZ_subnet.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.codeaffen.phpipam.plugins.modules.subnet', init_globals=dict(_module_fqn='ansible_collections.codeaffen.phpipam.plugins.modules.subnet', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py", line 258, in <module>
  File "/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py", line 253, in main
  File "/opt/homebrew/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 99, in api_connection
  File "/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 111, in connect
  File "/opt/homebrew/lib/python3.11/site-packages/phpypam/core/api.py", line 70, in __init__
    self._login()
  File "/opt/homebrew/lib/python3.11/site-packages/phpypam/core/api.py", line 132, in _login
    resp = self._query(method=POST, auth=_auth)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/phpypam/core/api.py", line 124, in _query
    raise PHPyPAMException(code=result['code'], message=result['message'])
phpypam.core.exceptions.PHPyPAMException
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/myuser/.ansible/tmp/ansible-tmp-1701953976.2923598-86153-236914147207910/AnsiballZ_subnet.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/myuser/.ansible/tmp/ansible-tmp-1701953976.2923598-86153-236914147207910/AnsiballZ_subnet.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/myuser/.ansible/tmp/ansible-tmp-1701953976.2923598-86153-236914147207910/AnsiballZ_subnet.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.codeaffen.phpipam.plugins.modules.subnet', init_globals=dict(_module_fqn='ansible_collections.codeaffen.phpipam.plugins.modules.subnet', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py\", line 258, in <module>\n  File \"/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/subnet.py\", line 253, in main\n  File \"/opt/homebrew/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py\", line 137, in __enter__\n    return next(self.gen)\n           ^^^^^^^^^^^^^^\n  File \"/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 99, in api_connection\n  File \"/var/folders/z5/8gjws59117v_1sbh43ncnnq80000gq/T/ansible_codeaffen.phpipam.subnet_payload_fe0qvq2d/ansible_codeaffen.phpipam.subnet_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 111, in connect\n  File \"/opt/homebrew/lib/python3.11/site-packages/phpypam/core/api.py\", line 70, in __init__\n    self._login()\n  File \"/opt/homebrew/lib/python3.11/site-packages/phpypam/core/api.py\", line 132, in _login\n    resp = self._query(method=POST, auth=_auth)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/opt/homebrew/lib/python3.11/site-packages/phpypam/core/api.py\", line 124, in _query\n    raise PHPyPAMException(code=result['code'], message=result['message'])\nphpypam.core.exceptions.PHPyPAMException\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

I'm using the latest version of the Galaxy colection:

ansible-galaxy collection list|grep phpipam
codeaffen.phpipam 1.7.0

python -V
Python 3.11.6

To Reproduce
Steps to reproduce the behavior:

  1. Run playbook against phpIPAM v1.6

Expected behavior
Subnet to be added

Versions:

  • Ansible:

    $ ansible [core 2.16.1]
  • phpipam-ansible-modules:

    $ ansible-galaxy collection list codeaffen.phpipam
    
    1.7.0
  • phpypam:

    $ pip freeze | grep phpypam
    
     phpypam==1.0.2
  • phpIPAM:

    $ phpIPAM IP address management [v1.6.0] dbversion 39
  • python version

    $ Python 3.11.6
  • list of python libraries:

    $ pip freeze

Additional context
Add any other context about the problem here.

`ipaddress` not a supported parameter

Describe the bug

Neither ipaddress nor one of its aliases ip or address are supported parameters in address module.

To Reproduce

  1. create a ansible task/play:
- name: "create address '{{ address.ipaddress }}'"
  codeaffen.phpipam.subnet:
    username: "{{ phpipam_admin }}"
    password: "{{ phpipam_admin_password }}"
    server_url: "https://ipam.example.com"
    app_id: "{{ phpipam_app_id }}"
    validate_certs: "{{ validate_certs }}"
    ipaddress: "{{ address.ipaddress }}"
    subnet: "{{ address.subnet }}"
    hostname: "{{ address.hostname | default(omit) }}"
    description: "{{ addres.description | default(omit) }}"
    is_gateway: "{{ address.is_gateway | default('no') }}"
    state: present
  1. run these task and see error message:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (codeaffen.phpipam.subnet) module: address, hostname, is_gateway Supported parameters include: allow_requests, app_id, cidr, description, discover_subnet, dns_records, dns_recursive, is_folder, is_full, linked_subnet, location, mask, nameserver, parent, password, permissions, ping_subnet, scan_agent, section, server_url, show_as_name, state, subnet, subnet_state, threshold, username, validate_certs, vlan, vrf"}

Expected behavior

No errors should be raised. Entity should be managed.

Versions:

  • Ansible: 2.9.x
  • phpipam-ansible-modules: 1.1.1
  • phpypam: 1.0.0

Specifying a tag for an address fails with `phpypam.core.exceptions.PHPyPAMInvalidSyntax: Invalid filter_by` error

Describe the bug

When specifying a tag for a codeaffen.phpipam.address, the task fails with the error phpypam.core.exceptions.PHPyPAMInvalidSyntax: Invalid filter_by

To Reproduce
Steps to reproduce the behavior:

Define a task that looks something like the task below—with a tag specified as a string value.

  - codeaffen.phpipam.address:
      username: my_phpipam_username
      password: my_phpipam_password
      server_url: https://myphpiamserver.local
      app_id: my_phpipam_app
      section: my_subnet_section
      ipaddress: 10.20.0.1
      tag: Reserved
      subnet: 10.20.0.0/24

Expected behavior

I expect the address to be added to phpIPAM and the tag to have been resolved correctly.

Versions:

  • Ansible: core 2.11.6
  • phpipam-ansible-modules: 1.3.1
  • phpypam: 1.0.2

Additional context

This appears to be because the responses from the tools/tags endpoint does not include a tag attribute, but rather the tag string is returned in a type attribute. This does not follow the convention that is expected by default in PhpipamAnsibleModule.find_by_key

Refactor subnet module to handle either parent or folder

Is your feature request related to a problem? Please describe.

Currently the subnet module can handle nested subnets via the parent parameter. As phpIPAM handles subnets and folders in the same namespace we need to refactor our subnet module.

Describe the solution you'd like

We propose to manage either parent or folder in separate parameters in subnet module. These parameters needs to be mutual exclusive. This way we have the chance to use the current phpipam_helper.py methods to resolve given names/cidrs to an id.

Describe alternatives you've considered

Another solution could be the recycling of the existing parent parameter to use for either a containing subnet or folder. This solution needs more efford to be implemented as we need to cover all possible issues related to wrong user inputs.

Additional context

No matter which solution will be implemented the parameter is_folder needs to be removed from subnet module as folders will be managed by its own module.

Add VLAN-s with same number to different l2 domains

Is your feature request related to a problem? Please describe.
I have created multiple l2 domains. I want to create a vlan3 in l2 domain number 1. It creates it. Now I want to create a vlan3 in l2 domain number 2. It wont create it.

Describe the solution you'd like
Create vlans with same number and name in different l2 domains.

Describe alternatives you've considered
Create the vlans using GUI.

image

image

image

Additional context

With the latest change from cmeissner in branch bugfix/80 that was merged to develop in codeaffen/php-ansible-modules I can not create vlans at all with the settings i wish.

failed: [REDACATED] (item={'vlan_id': '3', 'name': 'test1', 'description': 'test1', 'routing_domain': 'test_domain'}) => {"ansible_loop_var": "vlan", "changed": false, "msg": "Found no results while searching for vlan at /", "vlan": {"description": "test1", "name": "test1", "routing_domain": "test_domain", "vlan_id": "3"}}
failed: [REDACTED] (item={'vlan_id': '3', 'name': 'test2', 'description': 'test2', 'routing_domain': 'test_domain_2'}) => {"ansible_loop_var": "vlan", "changed": false, "msg": "Found no results while searching for vlan at /", "vlan": {"description": "test2", "name": "test2", "routing_domain": "test_domain_2", "vlan_id": "3"}}
#tasks
- name: IPAM create sections 
  codeaffen.phpipam.section:
    app_id: "ansible"
    username: "admin"
    password: "{{ docker_compose_ipam_admin_password }}"
    server_url: "https://{{ inventory_hostname }}"
    name: "{{ section.name }}"
    description: "{{ section.description }}"
    state: present
  loop: "{{ docker_compose_ipam_sections }}"
  loop_control:
    loop_var: section
  tags: admin_tasks_phpipam

- name: IPAM create L2 domains 
  codeaffen.phpipam.domain:
    app_id: "ansible"
    username: "admin"
    password: "{{ docker_compose_ipam_admin_password }}"
    server_url: "https://{{ inventory_hostname }}"
    name: "{{ l2_domain.name }}"
    description: "{{ l2_domain.description }}"
    sections: "{{ l2_domain.sections }}"
    state: present
  loop: "{{ docker_compose_ipam_l2_domains }}"
  loop_control:
    loop_var: l2_domain
  tags: admin_tasks_phpipam

- name: Create VLANS.
  codeaffen.phpipam.vlan:
    app_id: "ansible"
    username: "admin"
    password: "{{ docker_compose_ipam_admin_password }}"
    server_url: "https://{{ inventory_hostname }}"
    description: "{{ vlan.description }}"
    name: "{{ vlan.name }}"
    vlan_id: "{{ vlan.vlan_id }}"
    routing_domain: "{{ vlan.routing_domain }}"
    state: present
  loop: "{{ docker_compose_ipam_vlans }}"
  loop_control:
    loop_var: vlan
  tags: admin_tasks_phpipam

- name: Create IP subnets.
  codeaffen.phpipam.subnet:
    app_id: "ansible"
    username: "admin"
    password: "{{ docker_compose_ipam_admin_password }}"
    server_url: "https://{{ inventory_hostname }}"
    description: "{{ subnet.description }}"
    cidr: "{{ subnet.cidr }}"
    section: "{{ subnet.section }}"
    location: "{{ subnet.location|default(omit) }}"
    vlan: "{{ subnet.vlan|default(omit) }}"
      #discover_subnet: "{{ subnet.discover_subnet }}"
    dns_records: "{{ subnet.dns_records|default(omit) }}"
    nameserver: "{{ subnet.nameserver|default(omit) }}"
    state: present
  loop: "{{ docker_compose_ipam_subnets }}"
  loop_control:
    loop_var: subnet
  tags: admin_tasks_phpipam
#vars

docker_compose_ipam_sections:
  - name: "test_section"
    description: "test_section" 

docker_compose_ipam_l2_domains:
  - name: "test_domain" 
    description: "test_domain"
    sections:
      - "test_section"
  - name: "test_domain_2" 
    description: "test_domain_2"
    sections:
      - "test_section"

docker_compose_ipam_vlans:
  - vlan_id: "3"
    name: "test1"
    description: "test1"
    routing_domain: "test_domain"
  - vlan_id: "3"
    name: "test2"
    description: "test2"
    routing_domain: "test_domain_2"

docker_compose_ipam_subnets:
  - cidr: "192.168.1.0/24"
    section: "test_section"
    vlan: "3"
    description: "test"

Unable to create subnet in folder

Describe the bug
When creating a subnet, there is no way to specify in which folder it should be placed. Apparently the "master_folder" option is missing. This is possible through the web interface.

Screenshot:
image

Versions:

  • Ansible: 2.13
  • phpipam-ansible-modules: 1.6.1
  • phpypam:1.0.2
  • phpIPAM: 1.4

Additional context
Add any other context about the problem here.

add automatic testing facility for all modules

Is your feature request related to a problem? Please describe.

It would be great to run all existing tests always against a fresh phpipam installation. The benefit will that the tests run always again a defined setup. The project also don't need to provide a test environment.

Describe the solution you'd like

A github workflow need to be created where a phpipam environment is pinned up. The setup env needs to be configured that tess-all target uses this phpipam installation

Describe alternatives you've considered

a solution in circleci can be an alternative.

Get method support

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
I would like to be able to pull descriptive data from all areas of PHPIPAM. This would be accomplished with the implantation of the GET section of the APIs.

Describe alternatives you've considered
I am considering building my own Python library to parse the data and pass the data through to Ansible. But, I would prefer to utilizing this repository.

Additional context
I am wanting to start working of the feature myself.

Cut off phpipam api calls from `phpipam_utils.py` to make it more plugins available.

Is your feature request related to a problem? Please describe.
In the early beginning of this project we decided to put all api calls inside classes where all modules derive from.
This was fine until we want to start developing plugins such as lookup and inventory plugins. This plugin classes can not be derived from PhpipamAnsibleModule or PhpipamEntityAnsibleModule.

Describe the solution you'd like
Now it is time to create a module which provides a phpipam related classes and methods in a way we can use it for all kinds of plugins.
After creating such a module we can use it for all our plugins and modules. Another benifit will be that we can hide handling of strange different api calls from the user but we provide a common way. See it like a layer of abstraction.

Trouble creating subnet with a vrf

Describe the bug
Cant assign a subnet with a custom vrf

To Reproduce
Steps to reproduce the behavior:

  - name: "Create subnet"
    codeaffen.phpipam.subnet:
       app_id: "ansible"
       username: "ansible"
       password: "{{password}}"
       server_url: "https://ipam.internal"
       cidr: "192.168.1.0/27"
       parent: "192.168.1.0/24"
       vlan: "1337"
       vrf: FW-Linknets
       location: "DC1"
       validate_certs: no
       section: "Linknets"
       routing_domain: DC1

Expected behavior
A clear and concise description of what you expected to happen.
Have the subnet created in the correct subnets

Versions:

  • Ansible: core 2.12.3
  • phpipam-ansible-modules: 1.6.0
  • phpypam: Version: 1.0.2

Additional context
I see this error:

      }
   },
   "msg": "Can not resolve 'vrf' to an existing ID"
}

Creating same subnet in different sections isn't possible

Describe the bug

If I want to create the same subnet within different section that won't work correctly. The subnet will be created first in one group and after that the section parameter is changed to the next section.

$ ansible-playbook example_setup.yml

PLAY [localhost] **************************************************************************************************************************************************************************************************

TASK [create sections] ********************************************************************************************************************************************************************************************
included: phpipam-ansible-modules/tasks/section.yml for localhost => (item={'name': 'Customer A', 'parent': 'Customers'})
included: phpipam-ansible-modules/tasks/section.yml for localhost => (item={'name': 'Customer B', 'parent': 'Customers'})

TASK [Ensure state of section: Customer A] ************************************************************************************************************************************************************************
changed: [localhost]

TASK [Ensure state of section: Customer B] ************************************************************************************************************************************************************************
changed: [localhost]

TASK [create subnet] **********************************************************************************************************************************************************************************************
included: phpipam-ansible-modules/tasks/subnet.yml for localhost => (item={'cidr': '192.0.2.0/24', 'section': 'Customer A'})
included: phpipam-ansible-modules/tasks/subnet.yml for localhost => (item={'cidr': '192.0.2.0/24', 'section': 'Customer B'})

TASK [Ensure state of subnet: 192.0.2.0/24] ***********************************************************************************************************************************************************************
changed: [localhost]

TASK [Ensure state of subnet: 192.0.2.0/24] ***********************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=8    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

image

To Reproduce

  1. Create following configs:
    section.yml
---
sections:
  - name: "Customer A"
    parent: "Customers"
  - name: "Customer B"
    parent: "Customers"

subnet.yml

---
subnets:
  - cidr: 192.0.2.0/24
    section: "Customer A"
  - cidr: 192.0.2.0/24
    section: "Customer B"
  1. create task files for section and subnet
  2. create following playbook:
---
- hosts: localhost
  collections:
    - codeaffen.phpipam
  gather_facts: false
  vars_files:
    - vars/server.yml
    - vars/section.yml
    - vars/subnet.yml
  tasks:
    - name: create sections
      include: tasks/section.yml
      vars:
        name: "{{ section.name }}"
      loop: "{{ sections }}"
      loop_control:
        loop_var: section

    - name: create subnet
      include: tasks/subnet.yml
      vars:
        name: "{{ subnet.cidr }}"
      loop: "{{ subnets }}"
      loop_control:
        loop_var: subnet
  1. let the playbook run and see that ip subnet 192.0.2.0/24 is only assigned to Customer B.

Expected behavior

IP subnet 192.0.2.0/24 should be assigned to both sections Customer A and Customer B

Versions:

  • Ansible: 2.9.x
  • phpipam-ansible-modules: 1.2.0
  • phpypam: 1.0.0

Additional context

If we add the IP subnet manually to both sections we get another error:

TASK [create subnet] **********************************************************************************************************************************************************************************************
included: phpipam-ansible-modules/tasks/subnet.yml for localhost => (item={'cidr': '192.0.2.0/24', 'section': 'Customer A'}) 
included: phpipam-ansible-modules/tasks/subnet.yml for localhost => (item={'cidr': '192.0.2.0/24', 'section': 'Customer B'}) 

TASK [Ensure state of subnet: 192.0.2.0/24] ***********************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Found too many (2) results while searching for subnets at cidr/192.0.2.0/24"}

This is possibly because we don't accept result set greater than one.

Implement lookup plugin for `next_address` for a subnet in a given section

Is your feature request related to a problem? Please describe.

It would be a good idea to have a lookup plugin to get the next free ip address for a subnet in a given section.

Describe the solution you'd like

There should be a lookup plugin (e.g. codeaffen.phpipam.next_address) which return the next free ip address for a subnet for in a given section.

E.g.

- name: get next ip address
  vars:
    ip: "{{ query('codeaffen.phpipam.next_address', server_url='ipam.example.com', app_id='ansible', username='username', password='password', subnet='192.0.2.0/24', section='DevOps Dept.') }}"

Describe alternatives you've considered

Alternatively we need to implement all the steps needed to get the next ip address by hand.

provide environment variable support for connection data

Is your feature request related to a problem? Please describe.

Currently you can define connection parameters only within a task definition. Sometimes it will be useful to provide connection data via environment variables (e.g. overriding certificate checking in test environments).

Describe the solution you'd like

phpipam_helper.py needs to updated to use env_fallback and fallback for connection parameters.

problem with folder creation

Can not create folder

To Reproduce
Steps to reproduce the behavior:

  1. Play:
  • name: Create a folder in DC
    folder:
    app_id: "{{ app_id }}"
    username: "{{ username }}"
    password: "{{ password }}"
    server_url: "{{ server_url }}"
    name: "folder_name"
    section: "section_name"
    state: present
    collections:
    • codeaffen.phpipam
  1. Debug output:

Traceback (most recent call last):
File "/home/username/.ansible/tmp/ansible-tmp-1693814655.9445152-342929-70018326159780/AnsiballZ_folder.py", line 107, in
_ansiballz_main()
File "/home/username/.ansible/tmp/ansible-tmp-1693814655.9445152-342929-70018326159780/AnsiballZ_folder.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/home/username/.ansible/tmp/ansible-tmp-1693814655.9445152-342929-70018326159780/AnsiballZ_folder.py", line 47, in invoke_module
runpy.run_module(mod_name='ansible_collections.codeaffen.phpipam.plugins.modules.folder', init_globals=dict(_module_fqn='ansible_collections.codeaffen.phpipam.plugins.modules.folder', modlib_path=modlib_path),
File "/usr/lib/python3.8/runpy.py", line 207, in run_module
return run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 97, in run_module_code
run_code(code, mod_globals, init_globals,
File "/usr/lib/python3.8/runpy.py", line 87, in run_code
exec(code, run_globals)
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 109, in
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 105, in main
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 600, in run
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 342, in auto_resolve_entities
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 302, in resolve_entity
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 230, in find_folder
File "/tmp/ansible_folder_payload_g45d7f9
/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 122, in find_entity
File "/home/username/ansible/lib/python3.8/site-packages/phpypam/core/api.py", line 167, in get_entity
return self._query(token=self._api_token, method=GET, path=_path, params=_params)
File "/home/username/ansible/lib/python3.8/site-packages/phpypam/core/api.py", line 124, in _query
raise PHPyPAMException(code=result['code'], message=result['message'])
File "/home/username/ansible/lib/python3.8/site-packages/phpypam/core/exceptions.py", line 44, in init
raise PHPyPAMInvalidSyntax(message=self._message)
phpypam.core.exceptions.PHPyPAMInvalidSyntax: Invalid filter_by
fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n File "/home/username/.ansible/tmp/ansible-tmp-1693814655.9445152-342929-70018326159780/AnsiballZ_folder.py", line 107, in \n _ansiballz_main()\n File "/home/username/.ansible/tmp/ansible-tmp-1693814655.9445152-342929-70018326159780/AnsiballZ_folder.py", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File "/home/username/.ansible/tmp/ansible-tmp-1693814655.9445152-342929-70018326159780/AnsiballZ_folder.py", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.codeaffen.phpipam.plugins.modules.folder', init_globals=dict(_module_fqn='ansible_collections.codeaffen.phpipam.plugins.modules.folder', modlib_path=modlib_path),\n File "/usr/lib/python3.8/runpy.py", line 207, in run_module\n return run_module_code(code, init_globals, run_name, mod_spec)\n File "/usr/lib/python3.8/runpy.py", line 97, in run_module_code\n run_code(code, mod_globals, init_globals,\n File "/usr/lib/python3.8/runpy.py", line 87, in run_code\n exec(code, run_globals)\n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 109, in \n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 105, in main\n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 600, in run\n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 342, in auto_resolve_entities\n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 302, in resolve_entity\n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 230, in find_folder\n File "/tmp/ansible_folder_payload_g45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 122, in find_entity\n File "/home/username/ansible/lib/python3.8/site-packages/phpypam/core/api.py", line 167, in get_entity\n return self._query(token=self._api_token, method=GET, path=_path, params=_params)\n File "/home/username/ansible/lib/python3.8/site-packages/phpypam/core/api.py", line 124, in _query\n raise PHPyPAMException(code=result['code'], message=result['message'])\n File "/home/username/ansible/lib/python3.8/site-packages/phpypam/core/exceptions.py", line 44, in init\n raise PHPyPAMInvalidSyntax(message=self._message)\nphpypam.core.exceptions.PHPyPAMInvalidSyntax: Invalid filter_by\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}

Expected behavior
Folder created

Versions:

  • Ansible: 2.13
  • phpipam-ansible-modules: 1.7.0
  • phpypam: 1.0.2
  • phpIPAM: 1.4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.