I am trying to add a couple of v7 devices into Ansible and as the standard commands appear to fail with v7 I'm looking to replicate the following playbook tasks into a Rest API query.
Task 1:
Code: Select all
- name: Adding VLAN to parent interface
routeros_command:
commands:
- /interface/vlan/add vlan-id=123 name=123 interface=[/interface/get [/interface/find comment~"{{HE_FNN}}"] name]
Code: Select all
- name: Adding IP address to parent VLAN
routeros_command:
commands:
- /ip address add address $Svc_IP interface=$vlan_id comment='Cust: {{Cust_Name}} ['{{Svc_BW}}'] ('{{Svc_Car}}') {'{{Svc_ID}}'}'
Looking through the limited documentation of the REST API i'm striking out in trying to complete the first task of creating a VLAN without searching for a specific interface based on a unique identifier in the comment.
Playbook:
Code: Select all
---
- hosts: all
connection: network_cli
gather_facts: false
vars:
ansible_network_os: routeros
tasks:
- name: Adding VLAN to parent interface
uri:
url: "{{item.url}}"
method: PUT
url_username: username
url_password: password_is_secure_goes_brrr
force_basic_auth: yes
validate_certs: false
body_format: json
body: {}
register: results
loop:
- {url: 'https://X.X.X.X/rest/interface/vlan', body: '{vlan-id: "69",name: "69",interface: "sfp-sfpplus8"}' }
Code: Select all
"item": {
"body": "{vlan-id: \"69\",name: \"69\",interface: \"sfp-sfpplus8\"}",
"url": "https://X.X.X.X/rest/interface/vlan"
},
"json": {
"detail": "failure: vlan-id bad",
"error": 400,
"message": "Bad Request"
},
"msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request",
"redirected": false,
"status": 400,
"url": "https://X.X.X.X/rest/interface/vlan",
"x_frame_options": "sameorigin"