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

Error creating rack_group with location name: Location needs a valid UUID #286

Closed
nicholaskuechler opened this issue Nov 30, 2023 · 4 comments · Fixed by #287
Closed

Error creating rack_group with location name: Location needs a valid UUID #286

nicholaskuechler opened this issue Nov 30, 2023 · 4 comments · Fixed by #287
Assignees

Comments

@nicholaskuechler
Copy link
Contributor

ISSUE TYPE
  • Bug Report
SOFTWARE VERSIONS
pynautobot

pynautobot==2.0.1

Ansible:

ansible==8.5.0

Nautobot:

2.0.5

SUMMARY

When I try to add a rack group using the location's friendly name, such as Location1, I get an error saying I need to use the Location UUID: msg: Location needs a valid UUID.

I'm using the example snippet for creating a rack group from: https://nautobot-ansible.readthedocs.io/en/latest/plugins/rack_group_module.html#examples

Related Slack thread: https://networktocode.slack.com/archives/C01NWPK6WHL/p1701378500094129

STEPS TO REPRODUCE
EXPECTED RESULTS

Expected the new rack group to be created and attached to the specified location.

ACTUAL RESULTS
TASK [rack_groups : Create rack group within Nautobot with only required information]
fatal: [0.0.0.0]: FAILED! => changed=false
  msg: Location needs a valid UUID
@nicholaskuechler
Copy link
Contributor Author

The location can be specified 2 different ways using nautobot api:

1.) Using location friendly name:

curl -X "POST" "http://0.0.0.0:8000/api/dcim/rack-groups/" \
     -H 'Authorization: Token 0123456789abcdef0123456789abcdef01234567' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "name": "TestABC",
  "location": {
    "name": "Location1"
  }
}'

2.) Using location UUID:

curl -X "POST" "http://0.0.0.0:8000/api/dcim/rack-groups/" \
     -H 'Authorization: Token 0123456789abcdef0123456789abcdef01234567' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "name": "TestDEF",
  "location": "250f0616-30a7-47ca-b230-92d1caf160d1"
}'

Notice the location being a dictionary object with friendly name versus a string with the location uuid.

I made some ansible to create the location using the api rather than the nautobot-ansible module as a temporary solution:

- name: Create default rack_groups
  ansible.builtin.uri:
    url: "{{ nautobot_url }}/api/dcim/rack-groups/"
    method: POST
    headers:
      Authorization: "Token {{ nautobot_token }}"
    body_format: json
    body:
      name: "{{ item.name }}"
      location:
        name: "{{ item.location }}"
    status_code: [201, 400]
  loop: "{{ rack_groups_defaults }}"

@joewesch
Copy link
Contributor

joewesch commented Dec 1, 2023

I see that there were a few lines added as part of the 2.0 migration:

elif k == "location":
self._handle_errors(msg="Location needs a valid UUID")

There could be a valid reason, or it could have just been a misunderstanding. Let me investigate and either update the documentation or remove that limitation.

@joewesch
Copy link
Contributor

joewesch commented Dec 1, 2023

Also, you may be interested to know we have many lookup plugins so you don't need to reinvent the wheel with the URI module:

test_location: "{{ lookup('networktocode.nautobot.lookup', 'locations', api_endpoint=nautobot_url, token=nautobot_token, api_filter='name=\"Child Test Location\"') }}"

@jvanderaa
Copy link
Contributor

@joewesch do you think we could handle this so the nice name can be provided?

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.

3 participants