2023-12-29 13:55:00 +00:00
|
|
|
# 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
|
|
|
|
|
2023-12-18 10:22:14 +00:00
|
|
|
- name: Set configuration
|
|
|
|
ansible.netcommon.cli_config:
|
2023-12-29 13:55:00 +00:00
|
|
|
config: '{{ config.json.content }}'
|
2023-12-18 10:22:14 +00:00
|
|
|
register: result
|
|
|
|
# These lines are not displayed by 'sho ru' and always reported as different, so ignore them.
|
2023-12-29 13:55:00 +00:00
|
|
|
changed_when: result.commands | reject('match', '^(no shutdown|no switchport access vlan|switchport mode access|switchport mode hybrid|interface .*)$')
|
2023-12-18 10:22:14 +00:00
|
|
|
notify: write config
|