access: move templates to netbox

And adjust tasks to work with FS switches also.
This commit is contained in:
Timotej Lazar 2023-12-29 14:55:00 +01:00
parent be398e54fe
commit 0802dc8637
3 changed files with 18 additions and 72 deletions

View file

@ -1,7 +1,17 @@
# This should be provided by the netbox inventory plugin but isn’t yet.
# https://github.com/netbox-community/ansible_modules/issues/1007
- name: Fetch configuration from netbox
uri:
url: '{{ interfaces[0].device.url }}render-config/' # why URL can only be accessed through interface data is a mystery
method: POST
headers:
Authorization: 'Token {{ lookup("env", "NETBOX_API_TOKEN") }}'
register: config
- name: Set configuration
ansible.netcommon.cli_config:
config: "{{ lookup('template', 'config.j2') }}"
config: '{{ config.json.content }}'
register: result
# These lines are not displayed by 'sho ru' and always reported as different, so ignore them.
changed_when: result.commands | reject('match', '^(no shutdown|no switchport access vlan|switchport mode hybrid|interface .*)$')
changed_when: result.commands | reject('match', '^(no shutdown|no switchport access vlan|switchport mode access|switchport mode hybrid|interface .*)$')
notify: write config