codeaffen / phpipam-ansible-modules

Ansible Modules to manage phpIPAM installations
https://codeaffen.org/projects/phpipam-ansible-modules
GNU General Public License v3.0
22 stars 10 forks source link

Cannot assign vlan to subnet with the subnet module #116

Closed eftner closed 8 months ago

eftner commented 10 months ago

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:

cmeissner commented 9 months ago

Hi @eftner,

Thank you for bringing this issue to our attention. I tried to reproduce it with our test case domain_vlan_subnet_mappin, but it runs as expected. Please try this also against your installation (I guess you mean 1.6.0). This version is not yet fully tested, but the before mentioned test case runs well.

To run the test against your installation, you need to do the following:

  1. clone our repo and switch to the source directory
  2. export some variables
    PYTHONWARNINGS="ignore:Unverified HTTPS request"
    PHPIPAM_VERSION="v1.6.0"
    PHPIPAM_PORT=8443
    PHPIPAM_URL=https://localhost:${PHPIPAM_PORT}
    PHPIPAM_APPID=ansible
    PHPIPAM_USERNAME=admin
    PHPIPAM_PASSWORD=ipamadmin
    PHPIPAM_VALIDATE_CERTS=false
    PHPIPAM_API_URL=https://localhost:8443/api/${PHPIPAM_APPID}
  3. run the test make test-domain_vlan_subnet_mapping
  4. optional run ansible-playbook -i tests/inventory/hosts tests/test_playbooks/domain_vlan_subnet_mapping.yml -vvv, to get more verbose output

To double-check the results against a local test installation, you can run make setup-phpipam to spin up a podman-compose (docker-compose) phpipam instance and run the test against this one. Before running the setup, you need to adjust the environment variables from step 2.

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 8 months ago

This issue was closed because it has been stalled for 5 days with no activity.