Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not create a child location type #463

Closed
turgay-smirnov opened this issue Dec 10, 2024 · 4 comments · Fixed by #465
Closed

Could not create a child location type #463

turgay-smirnov opened this issue Dec 10, 2024 · 4 comments · Fixed by #465
Assignees

Comments

@turgay-smirnov
Copy link

ISSUE TYPE
  • Bug Report
SOFTWARE VERSIONS
pynautobot

2.4.2

Ansible:

2.18.1

Nautobot:

2.3.6

Collection:

5.4.0

SUMMARY

When I try to create a child location type I got an error.

STEPS TO REPRODUCE
---
- hosts: localhost
  connection: local
  gather_facts: no
  collections:
    - networktocode.nautobot

  tasks:
    - name: Set Nautobot URL and Token from Environment Variable
      set_fact:
        api_token: "{{ lookup('ansible.builtin.env', 'NAUTOBOT_TOKEN') }}"
        nautobot_url: "{{ lookup('ansible.builtin.env', 'NAUTOBOT_URL') }}"

    - name: Parent Location Type
      networktocode.nautobot.location_type:
        url: "{{ nautobot_url }}"
        token: "{{ api_token }}"
        name: "ParentTest"
        content_types: ['dcim.device', 'dcim.rack']
        nestable: True

    - name: Child Location Type
      networktocode.nautobot.location_type:
        url: "{{ nautobot_url }}"
        token: "{{ api_token }}"
        name: "ChildTest"
        content_types: ['dcim.device', 'dcim.rack']
        parent:
          name: "ParentTest"
EXPECTED RESULTS

I expect that ChildTest is created

ACTUAL RESULTS
TASK [Child Location Type] ******************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'NoneType' object has no attribute 'intersection'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/turgay/.ansible/tmp/ansible-tmp-1733860547.4016168-72642-34048190517002/AnsiballZ_location_type.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/turgay/.ansible/tmp/ansible-tmp-1733860547.4016168-72642-34048190517002/AnsiballZ_location_type.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/turgay/.ansible/tmp/ansible-tmp-1733860547.4016168-72642-34048190517002/AnsiballZ_location_type.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.networktocode.nautobot.plugins.modules.location_type', init_globals=dict(_module_fqn='ansible_collections.networktocode.nautobot.plugins.modules.location_type', _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 \"/tmp/ansible_networktocode.nautobot.location_type_payload_yjy16x_w/ansible_networktocode.nautobot.location_type_payload.zip/ansible_collections/networktocode/nautobot/plugins/modules/location_type.py\", line 139, in <module>\n  File \"/tmp/ansible_networktocode.nautobot.location_type_payload_yjy16x_w/ansible_networktocode.nautobot.location_type_payload.zip/ansible_collections/networktocode/nautobot/plugins/modules/location_type.py\", line 134, in main\n  File \"/tmp/ansible_networktocode.nautobot.location_type_payload_yjy16x_w/ansible_networktocode.nautobot.location_type_payload.zip/ansible_collections/networktocode/nautobot/plugins/module_utils/utils.py\", line 588, in __init__\n  File \"/tmp/ansible_networktocode.nautobot.location_type_payload_yjy16x_w/ansible_networktocode.nautobot.location_type_payload.zip/ansible_collections/networktocode/nautobot/plugins/module_utils/utils.py\", line 934, in _find_ids\n  File \"/tmp/ansible_networktocode.nautobot.location_type_payload_yjy16x_w/ansible_networktocode.nautobot.location_type_payload.zip/ansible_collections/networktocode/nautobot/plugins/module_utils/utils.py\", line 791, in _build_query_params\nAttributeError: 'NoneType' object has no attribute 'intersection'\n", "module_stdout": "", "msg": "MODULE FAILURE: No start of json char found\nSee stdout/stderr for the exact error", "rc": 1}
How to fix

I think in dictionary ALLOWED_QUERY_PARAMS in file plugins/module_utils/utils.py there should be the following item:

"parent_location_type": set(["name"])
@turgay-smirnov
Copy link
Author

It looks like the correct syntax is as follows

---
- hosts: localhost
  connection: local
  gather_facts: no
  collections:
    - networktocode.nautobot

  tasks:
    - name: Set Nautobot URL and Token from Environment Variable
      set_fact:
        api_token: "{{ lookup('ansible.builtin.env', 'NAUTOBOT_TOKEN') }}"
        nautobot_url: "{{ lookup('ansible.builtin.env', 'NAUTOBOT_URL') }}"

    - name: Parent Location Type
      networktocode.nautobot.location_type:
        url: "{{ nautobot_url }}"
        token: "{{ api_token }}"
        name: "ParentTest"
        content_types: ['dcim.device', 'dcim.rack']
        nestable: True

    - name: Child Location Type
      networktocode.nautobot.location_type:
        url: "{{ nautobot_url }}"
        token: "{{ api_token }}"
        name: "ChildTest"
        content_types: ['dcim.device', 'dcim.rack']
        parent: "ParentTest"

@joewesch
Copy link
Contributor

@turgay-smirnov, I typically strive to allow both forms. I'll re-open this issue as something we should clean up to allow in a future release. I'm glad you found a workaround for now, though.

@joewesch joewesch reopened this Dec 11, 2024
@turgay-smirnov
Copy link
Author

@joewesch
I have two workarounds:

  1. In my first comment there is a section 'How to fix'. Do you think this is the way?
  2. Do not use nested dictionary with 'name' key.

@joewesch
Copy link
Contributor

In my first comment there is a section 'How to fix'. Do you think this is the way?

Yes, that would be a good guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants