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

problem with folder creation #107

Closed ingvarrwvw closed 1 year ago

ingvarrwvw commented 1 year ago

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
  2. 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_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 109, in File "/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 105, in main File "/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 600, in run File "/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 342, in _auto_resolve_entities File "/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 302, in _resolve_entity File "/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 230, in find_folder File "/tmp/ansible_folder_payloadg45d7f9/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_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py\", line 109, in \n File \"/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py\", line 105, in main\n File \"/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 600, in run\n File \"/tmp/ansible_folder_payloadg45d7f9/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_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 302, in _resolve_entity\n File \"/tmp/ansible_folder_payloadg45d7f9/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py\", line 230, in find_folder\n File \"/tmp/ansible_folder_payloadg45d7f9/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:

cmeissner commented 1 year ago

Hi @ingvarrwvw

thank you for bringing this issue to our attention. As already mentioned in your origin issue https://github.com/codeaffen/phpipam-ansible-modules/issues/100#issuecomment-1695398081 we are not able to reproduce the issue on our side.

So to dig a bit deeper please attache the output of the following commands:

pip freeze | grep php
ansible --version
ansible-galaxy collection list codeaffen.phpipam

After that please run the following commands in a python shell. Please make sure to adapt values for the api connection and section_id to reflect your setup.

>>> import phpypam
>>> pi = phpypam.api(
... url='https://localhost:8443',
... app_id='ansible',
... username='admin',
... password='XXX',
... ssl_verify=False
... )
>>> section_id=1
>>> lookup_params = { 
...     'filter_by': 'isFolder',
...     'filter_value': "1",
... }
pi.get_entity(controller='sections', controller_path=f'/{section_id}/subnets/', params=lookup_params)

It this command will fail, please run the following commands. You should also adapt the values for api connection and the section where to find the folders.

$ IPAM_TOKEN="$(curl -ks -XPOST --user admin https://localhost:8443/api/ansible/user/ | jq -r '.data.token')"
Enter host password for user 'admin':
$ curl -sk -XGET -H "token: ${IPAM_TOKEN}" https://localhost:8443/api/ansible/sections/1/subnets\&filter_by\='isFolder'\&filter_value\='1'
{"code":200,"success":true,"data":{"id":"1","name":"Customers","description":"Section for customers","masterSection":"0","permissions":"
ingvarrwvw commented 1 year ago

pip freeze | grep php: phpypam==1.0.2

ansible --version: ansible [core 2.13.7] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/username/ansible/lib/python3.8/site-packages/ansible ansible collection location = /home/username/.ansible/collections:/usr/share/ansible/collections executable location = /home/username/ansible/bin/ansible python version = 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] jinja version = 3.0.3 libyaml = True

ansible-galaxy collection list codeaffen.phpipam: /home/username/.ansible/collections/ansible_collections Collection Version codeaffen.phpipam 1.7.0

Python code work fine , returns a list of folders for the specified section

cmeissner commented 1 year ago

Ok, I tried to reproduce the issue but wasn't able. What I have done:

1. Created fresh pyenv

$ pyenv install 3.8.10
Downloading Python-3.8.10.tar.xz...
-> https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tar.xz
Installing Python-3.8.10...
Installed Python-3.8.10 to /home/username/.pyenv/versions/3.8.10
$ pyenv virtualenv 3.8.10 issue107
Looking in links: /tmp/tmpzzmm7320
Requirement already satisfied: setuptools in /home/username/.pyenv/versions/3.8.10/envs/issue107/lib/python3.8/site-packages (56.0.0)
Requirement already satisfied: pip in /home/username/.pyenv/versions/3.8.10/envs/issue107/lib/python3.8/site-packages (21.1.1)
$ pyenv activate issue107 
pyenv-virtualenv: version 'issue107' activated

2. Setup my environment

Most files I copied from <PAM-Repo>/test/test_playbook as they do not influence the overall result of the tests.

$ tree
.
├── ansible.cfg
├── folder.yml
├── hosts
├── requirements.txt
├── tasks
│   └── folder.yml
└── vars
    ├── folder.yml
    └── server.yml
$ ansible-galaxy collection install codeaffen.phpipam
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/codeaffen-phpipam-1.7.0.tar.gz to /home/username/.ansible/tmp/ansible-local-279942ai69nb5p/tmp4ruyszcw/codeaffen-phpipam-1.7.0-4o1trhng
Installing 'codeaffen.phpipam:1.7.0' to '/home/username/Development/tmp/personal/issue107/collections/ansible_collections/codeaffen/phpipam'
codeaffen.phpipam:1.7.0 was installed successfully
$ pip install -r requirements.txt
# long output ...
$ export PHPIPAM_VALIDATE_CERTS=false

3. Run test

ansible-playbook -i hosts folder.yml 

PLAY [Folder module tests] ******************************************************************************************************************************************************************************************

TASK [Create folder] ************************************************************************************************************************************************************************************************
included: /home/username/Development/tmp/personal/issue107/tasks/folder.yml for localhost

TASK [Ensure state of folder: create folder] ************************************************************************************************************************************************************************
changed: [localhost]

TASK [Create folder again, no change] *******************************************************************************************************************************************************************************
included: /home/username/Development/tmp/personal/issue107/tasks/folder.yml for localhost

TASK [Ensure state of folder: create folder again, no change] *******************************************************************************************************************************************************
ok: [localhost]

TASK [Delete folder] ************************************************************************************************************************************************************************************************
included: /home/username/Development/tmp/personal/issue107/tasks/folder.yml for localhost

TASK [Ensure state of folder: delete folder] ************************************************************************************************************************************************************************
changed: [localhost]

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

Summarized I can still say I was not able to reproduce the issue. I would assume this is a local issue. Have you already tried to remove and install the collection? Alternatively can you please setup an environment like the one I described above?

ingvarrwvw commented 1 year ago

I built a docker image with python 3.9 and the same versions of ansible and collections, and get error:

File "/root/.ansible/tmp/ansible-tmp-1694156128.3168776-44-185766633089775/AnsiballZ_folder.py", line 107, in
_ansiballz_main()
File "/root/.ansible/tmp/ansible-tmp-1694156128.3168776-44-185766633089775/AnsiballZ_folder.py", line 99, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-tmp-1694156128.3168776-44-185766633089775/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 File "/usr/lib64/python3.9/runpy.py", line 225, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.9/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals)
"/tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 109, in
File /tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/modules/folder.py", line 105, in main
"/tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 602, in run "/tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 572, in ensure_entity "/tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 268, in find_current_e File "/tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 230, in find_folder File "/tmp/ansible_folder_payload_sm2kqql7/ansible_folder_payload.zip/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py", line 122, in find_entity File "/usr/local/lib/python3.9/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 "/usr/local/lib/python3.9/site-packages/phpypam/core/api.py", line 124, in _query
raise PHPyPAMException(code=result['code'], message=result['message'])
File "/usr/local/lib/python3.9/site-packages/phpypam/core/exceptions.py", line 44, in init
raise PHPyPAMInvalidSyntax(message=self._message)
phpypam.core.exceptions.PHPyPAMInvalidSyntax: Invalid filter_by

cmeissner commented 1 year ago

Sad to hear that this issue persists. Unfortunately there are no new information in you comment.

Did you run your test playbook against a new phpipam installation or against your existing?

Can you please provide the output from the following command. Please set PHPIPAM_INSTALL_PATH accordingly.

$ grep VERSION_VISIBLE ${PHPIPAM_INSTALL_PATH}/functions/version.php

Please provide also a full description (all scripts, playbooks etc) you use to reproduce the issue. Also always double check the behavior against a fresh phpipam installation. We need to find a way to reproduce the issue on our side. At the moment this is not possible which let us assume that this is a local issue.

cmeissner commented 1 year ago

@ingvarrwvw can you please run the following command and post the output here?

for p in $(ansible-config dump --format json | jq -r '.[] | select(.name == "COLLECTIONS_PATHS") | .value[]') ; do test -d ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils && md5sum ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py ; done
ingvarrwvw commented 1 year ago

for p in $(ansible-config dump --format json | jq -r '.[] | select(.name == "COLLECTIONS_PATHS") | .value[]') ; do test -d ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils && md5sum ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py ; done

ansible-config dump [core 2.13.7] - have not format options what version you using ?

ingvarrwvw commented 1 year ago

Sad to hear that this issue persists. Unfortunately there are no new information in you comment.

Did you run your test playbook against a new phpipam installation or against your existing?

Can you please provide the output from the following command. Please set PHPIPAM_INSTALL_PATH accordingly.

$ grep VERSION_VISIBLE ${PHPIPAM_INSTALL_PATH}/functions/version.php

Please provide also a full description (all scripts, playbooks etc) you use to reproduce the issue. Also always double check the behavior against a fresh phpipam installation. We need to find a way to reproduce the issue on our side. At the moment this is not possible which let us assume that this is a local issue.

I running test playbook against in my existing phpipam

Output grep command:

define("VERSION_VISIBLE", "1.4"); //visible version in footer e.g 1.3.2 define("SCRIPT_PREFIX", VERSION_VISIBLE.'_r'.REVISION.'_v'.DBVERSION); //css and js folder prefix to prevent caching issues

cmeissner commented 1 year ago

for p in $(ansible-config dump --format json | jq -r '.[] | select(.name == "COLLECTIONS_PATHS") | .value[]') ; do test -d ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils && md5sum ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py ; done

ansible-config dump [core 2.13.7] - have not format options what version you using ?

with your version you could run the following command:

for p in $(ansible-config dump | grep COLLECTIONS_PATHS | awk 'BEGIN {FS="="} {print $2}' | tr -d "[\[\]',]") ; do test -d ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils && md5sum ${p}/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py ; done
ingvarrwvw commented 1 year ago

done:

a4abff6c90eb153227b82a6d01d7f1b3 /home/username/.ansible/collections/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py

cmeissner commented 1 year ago

a4abff6c90eb153227b82a6d01d7f1b3 /home/username/.ansible/collections/ansible_collections/codeaffen/phpipam/plugins/module_utils/phpipam_helper.py

Okay with all the data we can conclude the following:

  1. the version of phpipam_helper.py is the one which is coming from galaxy
  2. the filter_by seem to work without our ansible module
  3. phpipam is obviously version 1.4.0

As it is neither possible to reproduce the failure within the collection test suite nor with a newly installed phpipam environment.

May I ask you to do the following:

  1. export some environment variables
    PYTHONWARNINGS="ignore:Unverified HTTPS request"
    PHPIPAM_VERSION=<desired version, e.g. 1.4.4>
    PHPIPAM_PORT=<your desired https port, default is 443>
    PHPIPAM_SERVER_URL=https://localhost:${PHPIPAM_PORT}
    PHPIPAM_APP_ID=<desired app_id>
    PHPIPAM_USERNAME=<your username, default admin>
    PHPIPAM_PASSWORD=<your password, default ipamadmin>
    PHPIPAM_VALIDATE_CERTS=false
  2. Install new phpipam environment (you can use projects docker-compose.yml)
  3. Install a clean python env (via venv/pyenv see)
  4. Install requirements
  5. install ansible-core (either your current version or a newer one)
  6. create a folder
    ansible -i hosts localhost -m codeaffen.phpipam.folder -a 'name=blafasel section=Customers state=present' -vvv
  7. delete the created folder (only if it was created successfully in step 6)
    ansible -i hosts localhost -m codeaffen.phpipam.folder -a 'name=blafasel section=Customers state=absent' -vvv

After running these steps please post all outputs to this case. I ran all these steps on different systems and always successful.

github-actions[bot] commented 1 year 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 1 year ago

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

ingvarrwvw commented 1 year ago

Hi! Im back,and I have some news for you about this issue:

  1. Using the ansible module I can successfully delete manually created folders via the web interface
  2. Using the ansible module, I can successfully create folders if the section already contains at least one folder. In detail, using the ansible module: I create a section - success I create a folder in this section - no success I create a folder in this section manually via the web interface - success I create a folder in this section using the ansible module - success

I hope this gives you an idea on how to solve the problem

ingvarrwvw commented 1 year ago

python script:

import phpypam

pi = phpypam.api( url='url', app_id='app_id', username='admin', password='password', ssl_verify=True ) print(pi.get_entity(controller='sections', controller_path='/section_id/subnets/', params={'filter_by': 'isFolder', 'filter_value': '1'}))

returns the same error as the ansible module:

Traceback (most recent call last): File "ensure_folders.py", line 18, in print(pi.get_entity(controller='sections', controller_path='/326/subnets/', params={'filter_by': 'isFolder', 'filter_value': '1'})) 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

The above is true for a section without folders. After creating manually at least one folder, the error disappears

cmeissner commented 1 year ago

Still can't be reproduces. Neither with Ansible nor with Python:

For Ansible, see https://github.com/cmeissner/phpipam-ansible-modules/actions/runs/6545848809 or run make test-folder in a test environment.

For Python, see the following output:

>>> pi = phpypam.api(
...     url='https://localhost:8443',
...     app_id='ansible',
...     username='admin',
...     password='ipamadmin',
...     ssl_verify=False
... )
>>> pi.create_entity(controller='sections', data={'name':'folder test','description':'folder test section'})
>>> section_id = pi.get_entity(controller='sections', controller_path='folder test')['id']
>>> pi.get_entity(controller='sections', controller_path=f'/{section_id}/subnets/', params={'filter_by':'isFolder','filter_value':'1'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.pyenv/versions/pam_3.9.11/lib/python3.9/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/user/.pyenv/versions/pam_3.9.11/lib/python3.9/site-packages/phpypam/core/api.py", line 124, in _query
    raise PHPyPAMException(code=result['code'], message=result['message'])
  File "/home/user/.pyenv/versions/pam_3.9.11/lib/python3.9/site-packages/phpypam/core/exceptions.py", line 39, in __init__
    raise PHPyPAMEntityNotFoundException(self._message)
phpypam.core.exceptions.PHPyPAMEntityNotFoundException: No subnets found

Finally, I try to reproduce the behavior with plain cURL commands, but it behaves also as expected (section 3 has is completely empty, section 1 has one folder in it):

$ PHPIPAM_TOKEN=$(curl -sk -XPOST ${PHPIPAM_URL}/api/${PHPIPAM_APPID}/user/ --user ${PHPIPAM_USERNAME}:${PHPIPAM_PASSWORD} | jq -r '.data.token')
$ curl -sk -XGET -H "phpipam-token: ${PHPIPAM_TOKEN}" ${PHPIPAM_API_URL}/sections/3/subnets/\?filter_by=isFolder\&filter_value='1' | jq
{
  "code": 404,
  "success": false,
  "message": "No subnets found",
  "time": 0.005
}
$ curl -sk -XGET -H "phpipam-token: ${PHPIPAM_TOKEN}" ${PHPIPAM_API_URL}/sections/1/subnets/\?filter_by=isFolder\&filter_value='1' | jq
{
  "code": 200,
  "success": true,
  "data": [
    {
      "id": "5",
      "subnet": "0.0.0.0",
      "mask": "",
      "sectionId": "1",
      "description": "My folder",
      "linked_subnet": null,
      "firewallAddressObject": null,
      "vrfId": "0",
      "masterSubnetId": "0",
      "allowRequests": "0",
      "vlanId": "0",
      "showName": "0",
      "device": "0",
      "permissions": "{\"3\":\"1\",\"2\":\"2\"}",
      "pingSubnet": "0",
      "discoverSubnet": "0",
      "resolveDNS": "0",
      "DNSrecursive": "0",
      "DNSrecords": "0",
      "nameserverId": "0",
      "scanAgent": null,
      "customer_id": null,
      "isFolder": "1",
      "isFull": "0",
      "isPool": "0",
      "tag": "2",
      "threshold": "0",
      "location": null,
      "editDate": null,
      "lastScan": null,
      "lastDiscovery": null
    }
  ],
  "time": 0.022
}

As we are still not able to reproduce the issue and still requested data from https://github.com/codeaffen/phpipam-ansible-modules/issues/107#issuecomment-1712460214 is missing, we would not reopen the issue. If you are able to reproduce the issue in a fresh environment, we can take a look.

ingvarrwvw commented 1 year ago

What version of PHP are you using?

cmeissner commented 1 year ago

What version of PHP are you using?

I'm using the v1.4 container image. No idea what pho version is installed there.

ingvarrwvw commented 1 year ago

I solved the problem:

//if(sizeof($result)==0) { $this->Response->throw_exception(200, "No subnets found"); } if(empty($result)) { $this->Response->throw_exception(404, "No subnets found"); }

in API side, file Sections.php

Thank you very much for your help and your time!

cmeissner commented 1 year ago

@ingvarrwvw thank you for letting us know. Some more tests with different phpipam versions shows that this issue exists in version <= 1.4.0.

for minor in {0..7}
do
  export PHPIPAM_VERSION=v1.4.${minor}
  docker-compose -f tests/docker/docker-compose.yml down &> /dev/null
  make setup-phpipam &> /dev/null
  echo -n "$PHPIPAM_VERSION " && make test-folder &> /dev/null && echo success || echo failed
done
v1.4.0 failed
v1.4.1 success
v1.4.2 success
v1.4.3 success
v1.4.4 success
v1.4.5 success
v1.4.6 success
v1.4.7 success

So I updated the documentation for folder module with the requirement of phpipam >= 1.4.1.