-
Notifications
You must be signed in to change notification settings - Fork 216
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
[Bug]: Automatic name-to-slug feature doesn't remove umlauts like Netbox GUI does #808
Comments
…trip before sub
I believe this needs to be fixed in netbox. Specifically, |
Maybe, maybe not. I definitely see the value in only allowing basic ASCII characters for values like the slug that essentially act as a unique identifier. If they'd allow RTL, non-breaking spaces, all the letter-lookalikes and other such Unicode goodness that wouldn't really result in a net usability benefit imo The displayname of all assets is already fully Unicode capable. Whether Netbox changes their rules for characters allowed in slugs in the future or not, I think this module should stay aligned with their behavior and currently that is to strip these characters out. Personally I'm from Germany and perfectly OK with that :) |
I see netbox-community/netbox#3741 In fact, netbox-community/netbox#3741 (comment) says that
So, again, I don't think coercing everything into ASCII is the correct approach. |
I am a little sorry for the lengthy response, I am not a native english speaker and I don't mean any of it as an attack. If Netbox' rules for this ever change, PR #809 can be rolled back to support the new behavior (aka unicode) and everything is going to be fine - but most importantly, no hard errors for the users due to invalid slugs. |
Hi, Thank you for your lengthy response. Your research matches a lot of what I also researched, and I think what I am driving towards is that we need to fix this bug in NetBox itself, rather than destructively replacing user inputs with ASCII only characters in the Ansible modules for NetBox. Specifically, the fact that every other object's slugify code needs to be fixed, not just the I should have made this more explicit in my responses, so I apologize. (P.S. Do not worry about your responses coming off as an attack. In fact, unless you had not said anything, to my mind you come off as a native english speaker, so do not feel obligated to apologize) |
Ok. The workaround we'll have to implement until that is addressed is to manually implement the correct slugification logic in ansible/jinja - posting because this may help others who run into this same issue: - name: Properly slugify site or other object names
debug:
msg: '{{ item | regex_replace("(?a)[^\-\.\w\s]", "") | trim | regex_replace("[\-\.\s]+", "-") | lower }}'
loop:
- Königliches Rechenzentrum
- Skåne
- Keep an eye on this site 👀 task output:
use in a full task to manually pass a valid slug: - name: Reproduce bug
netbox.netbox.netbox_site:
netbox_url: '{{ netbox_url }}'
netbox_token: '{{ netbox_token }}'
state: present
data:
name: '{{ item }}'
slug: '{{ item | regex_replace("(?a)[^\-\.\w\s]", "") | trim | regex_replace("[\-\.\s]+", "-") | lower }}'
tags: [FortiGate-Sync]
loop:
- Königliches Rechenzentrum
- Skåne
- Keep an eye on this site 👀 EDIT: This custom slug will then also have to be passed to every single task that creates an object which references an object whose slug would be auto-guessed wrong by this module. E.g. Once you've created a site "Skåne" with the proper slug "skne" then when you attempt to create a VLAN referencing that site: - name: Create VLANs
netbox.netbox.netbox_vlan:
netbox_url: '{{ netbox_url }}'
netbox_token: '{{ netbox_token }}'
state: present
data:
name: "{{ item.name }}"
site: '{{ item.site }}'
description: "Funny VLAN for bug repro"
vid: "{{ item.vlanid }}"
tags: [FortiGate-Sync]
loop:
- name: Funny-VLAN
site: Skåne
vlanid: 42 you will get an error again because the value passed for "site" is auto-slugified wrong again and so the site cannot be found:
so the manual slugification workaround will have to be applied at every single task e.g.: - name: Create VLANs
netbox.netbox.netbox_vlan:
netbox_url: '{{ netbox_url }}'
netbox_token: '{{ netbox_token }}'
state: present
data:
name: "{{ item.name }}"
site: '{{ item.site | regex_replace("(?a)[^\-\.\w\s]", "") | trim | regex_replace("[\-\.\s]+", "-") | lower }}'
description: "Funny VLAN for bug repro"
vid: "{{ item.vlanid }}"
tags: [FortiGate-Sync]
loop:
- name: Funny-VLAN
site: Skåne
vlanid: 42 |
I am looking for issues that we can re-open on the NetBox server side. netbox-community/netbox#3741 would be ideal to re-open but it is locked and I cannot unlock. Worst case I will open a new issue and link everything |
Ansible NetBox Collection version
3.7.1
Ansible version
NetBox version
v3.2.2
Python version
3.10
Steps to Reproduce
Expected Behavior
The three site names should be "slugified" to:
Observed Behavior
The task fails all site names with "umlauts" and creates the site with the emoji, but with a different slug than what the Netbox UI would use:
Netbox 3.2.2 UI slug for the last site:
What the netbox_site ansible action created (note the trailing hyphen):
I've prepared a PR to fix both of these issues (umlauts causing an error and emojis producing a trailing slash)
The text was updated successfully, but these errors were encountered: