access: move switch config templates back to this repo

Let’s keep it simple. Also editing templates in NetBox is a pain.
This commit is contained in:
Timotej Lazar 2024-04-08 10:48:10 +02:00
parent 1ffdea8e43
commit c479f90669
7 changed files with 128 additions and 11 deletions

View file

@ -2,19 +2,9 @@
set_fact:
ansible_ssh_pass: '{{ lookup("passwordstore", "switch/"~inventory_hostname, subkey="pass") }}'
# 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: '{{ config.json.content }}'
config: '{{ lookup("template", "config-"~manufacturer~"-"~device_type~".j2") }}'
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 access|switchport mode hybrid|interface .*|no enable service web-server https?)$')