-
Notifications
You must be signed in to change notification settings - Fork 218
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
[Feature]: netbox_device_interface - untagged_vlan can't be removed #330
Comments
What I'm thinking of doing is having the user set something like the following from your example:
And then in
|
@FragmentedPacket that will works, however it's not so intuitive compared to the tagged_vlan parameter which is implecitly removed when not specified . It will therefore also require an update of the documentation. |
Let me play around with it, but we already use the pattern for converting a Jinja strong to ID but definitely needs to be documented |
Maybe having the value as |
@FragmentedPacket In my opinion infrastructure as Code must be deterministic. So it's not a problem to have this type of behaviour. |
I think that this should follow what the other network modules are doing. There are modes of:
|
@FragmentedPacket what's the progress on adding the ability for users to set fields to None? I have another use case that could be useful to be able to do. Currently, with the |
Hi @andybro19, I have not and this would be a pretty big change so I haven't really had time to implement this. I do have some thoughts and am trying to think the best way to cover all the use cases without it increasing the complexity of these modules. This would cover all fields of an object rather than a single one. To @jvanderaa's point, there are tons of different states to implement to cover the full range of use cases. |
I agree with #330 (comment) - however that is going to take a lot of work to implement. |
Just wanted to share that I ran into this problem as well, with prefixes. Some of our prefixes that are not in any VLAN had erroneously been assigned a "VLAN 1" 🤦 So when updating these through ansible I had to make sure any VLAN information on these is removed. Here's the workaround I use and it works very well and is idempotent too: - name: Create prefixes with VLANs
netbox.netbox.netbox_prefix:
netbox_url: '{{ netbox_url }}'
netbox_token: '{{ netbox_token }}'
data:
prefix: "{{ item.subnet | ansible.netcommon.ipaddr('network/prefix') }}"
site: "{{ item.firewall_location_long_name }}"
description: '{{ item.comment }}'
status: Active
tags: [Ansible]
vlan:
name: "{{ item.name }}"
site: "{{ item.firewall_location_long_name }}"
state: present
loop: "{{ _address_objects | selectattr('vlanid', 'defined') | rejectattr('vlanid', 'none') }}"
loop_control:
label: "{{ item.firewall_location_short_name }}-{{ item.name }} ( {{ item.subnet }} )"
- name: Create prefixes without VLANs
netbox.netbox.netbox_prefix:
netbox_url: '{{ netbox_url }}'
netbox_token: '{{ netbox_token }}'
data:
prefix: "{{ item.subnet | ansible.netcommon.ipaddr('network/prefix') }}"
site: "{{ item.firewall_location_long_name }}"
description: '{{ item.comment }}'
status: Active
tags: [Ansible]
vlan: null # This doesn't unset any information, this is just ignored by the module, but explicit null is nicer to read for humans.
state: present
loop: >
{{
(_address_objects | selectattr('vlanid', 'undefined')) +
(_address_objects | selectattr('vlanid', 'defined') | selectattr('vlanid', 'none'))
}}
loop_control:
label: "{{ item.firewall_location_short_name }}-{{ item.name }} ( {{ item.subnet }} )"
register: _netbox_prefixes_no_vlan
# Because unsetting / nulling a property with the netbox.netbox.netbox_prefix module
# is not possible right now ( https://github.com/netbox-community/ansible_modules/issues/330 )
# we do a "manual" API call to Netbox to make sure VLAN-less networks do not have a VLAN set.
# This can happen when someone manually edits a prefix, and does it wrong (e.g. no VLAN != VLAN 1)!
- name: Unset any VLAN information for prefixes without VLAN
ansible.builtin.uri:
url: 'https://netbox.hlb-intern.de/api/ipam/prefixes/{{ item.id }}/'
method: PATCH
headers:
Content-Type: application/json
Authorization: "Token {{ netbox_token }}"
body_format: json
body:
vlan: null
loop: "{{ _netbox_prefixes_no_vlan.results | map(attribute='prefix') }}"
loop_control:
label: "{{ item.prefix }} - {{ item.description }}"
changed_when: true # This task only ever runs when a change needs to be made, so every run is a change
when: item.vlan is not none # Only run when VLAN information has to be corrected Basically, I have previously sourced all of my subnet/prefix information, transformed it into a data format I can work with easily and then put it into the variable Then I split the those into the prefixes that are in a VLAN ( This can of course be adapted to your data schema / formats and to any other netbox objects other than |
ISSUE TYPE
SOFTWARE VERSIONS
Ansible:
2.9.123
Netbox:
2.8.8
Collection:
1.0.1
SUMMARY
@FragmentedPacket
As disscussed on #322, I open an other issue to track the untagged removed vlan bug.
Thx
STEPS TO REPRODUCE
First run
second run
EXPECTED RESULTS
untagged Vlan removed
ACTUAL RESULTS
untagged Vlan not removed
The text was updated successfully, but these errors were encountered: