Hi folks,
I’m trying to use Ansible to automate the configuration of new switches on the network. So far I’ve had a pretty good understanding of the resources available for routeros but I’m stuck in how to simulate the “set” cli keyword in the Ansible playbook. I’m testing stuff out using the following Playbook where I’m looking to create the same effect as cli command “interface/bridge/set nameofbridge vlan-filtering=yes”:
---
- name: New switch configuration
hosts: test_routers
gather_facts: false
vars_prompt:
- name: username
prompt: "username"
private: false
- name: password
prompt: "password"
vars:
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: community.network.routeros
ansible_user: '{{ username }}'
ansible_password: '{{ password }}'
tasks:
## - debug:
## msg: '{{ password }}'
- name: "Enable vlan filtering on bridge"
ansible.builtin.uri:
url: https://192.168.94.1/rest/interface/bridge
method: PATCH
url_username: '{{ username }}'
url_password: '{{ password }}'
force_basic_auth: yes
validate_certs: false
body_format: json
body: {}
register: results
loop:
- {url: 'https://192.168.94.1/rest/interface/bridge/set/*17', body: '{"vlan-filtering":"yes"}'}
- debug:
var: results
For testing purposes I’m trying to enable vlan filtering on a bridge that is already up and running but I cannot get it to work. I’ve tried:
- Methods: PUT (creates a new bridge interface and throws an error about failed task), POST (just throws an error and does nothing), PATCH (ansible reports that all is well but the log file just says that the following cli commands were input from api (/interface set bridge; /interface bridge set bridge; /queue interface set bridge). I think PATCH is the one to use for “set” based on what I’ve read but I’m not sure
- URL changes in the loop segment of the playbook e.g., https://192.168.94.1/rest/interface/bridge/set/*17 (with interface .id) https://192.168.94.1/rest/interface/bridge (without set cli key word) https://192.168.94.1/rest/interface/bridge/*17 (with interface .id after bridge)
I’m just getting my feet wet with Ansible and I can’t find a lot of resources for Routeros. Please give me a hand If you need any other info (e.g., ansible errors) please let me know.