I would like to automate my home network and maybe apply this after test in production then, but I faced with an strange issue which cannot solve by myself.
So I have installed CHR and group_vars for "all" (Off course inventory as well):
Code: Select all
ansible_connection: ansible.netcommon.network_cli
ansible_network_os: community.routeros.routeros
ansible_port: 22
ansible_user: ansible
ansible_password: "1"
host_key_checking: false
Code: Select all
- hosts: all
name: Test
gather_facts: true
tasks:
- name: Check rule
community.routeros.command:
commands:
- :put [/ip firewall filter get [find where comment="1234567"]]
register: does_exist
- name: Debug
ansible.builtin.debug:
msg:
- "{{ does_exist.stdout }}"
Code: Select all
ansible [core 2.13.4]
config file = /home/aleksey/.ansible.cfg
configured module search path = ['/home/aleksey/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/aleksey/.local/lib/python3.10/site-packages/ansible
ansible collection location = /home/aleksey/.ansible/collections:/usr/share/ansible/collections
executable location = /home/aleksey/.local/bin/ansible
python version = 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0]
jinja version = 3.1.2
libyaml = True
Code: Select all
changed: [vbox2] => {
"changed": true,
"invocation": {
"module_args": {
"commands": [
":put [/ip firewall filter get [find where comment \"1234567\"]]"
],
"interval": 1,
"match": "all",
"retries": 10,
"wait_for": null
}
},
"stdout": [
"no such itemno such item"
],
"stdout_lines": [
[
"no such itemno such item"
]
]
}
changed: [vbox1] => {
"changed": true,
"invocation": {
"module_args": {
"commands": [
":put [/ip firewall filter get [find where comment \"1234567\"]]"
],
"interval": 1,
"match": "all",
"retries": 10,
"wait_for": null
}
},
"stdout": [
"no such itemno such item"
],
"stdout_lines": [
[
"no such itemno such item"
]
]
}
Code: Select all
changed: [vbox2] => {
"changed": true,
"invocation": {
"module_args": {
"commands": [
":put [/ip firewall filter get [find where comment \"12345678\"]]"
],
"interval": 1,
"match": "all",
"retries": 10,
"wait_for": null
}
},
"stdout": [
":put [/ip firewall filter get [find where comment \"12345678\"]\n<ter get [find where comment \"12345678\"]] \n<ter get [find where comment \"12345678\"]]\n<ter get [find where comment \"12345678\"]]\n\nno such item:put [/ip firewall filter get [find where comment \"12345678\"]\n<ter get [find where comment \"12345678\"]] \n<ter get [find where comment \"12345678\"]]\n<ter get [find where comment \"12345678\"]]\n\nno such item"
],
"stdout_lines": [
[
":put [/ip firewall filter get [find where comment \"12345678\"]",
"<ter get [find where comment \"12345678\"]] ",
"<ter get [find where comment \"12345678\"]]",
"<ter get [find where comment \"12345678\"]]",
"",
"no such item:put [/ip firewall filter get [find where comment \"12345678\"]",
"<ter get [find where comment \"12345678\"]] ",
"<ter get [find where comment \"12345678\"]]",
"<ter get [find where comment \"12345678\"]]",
"",
"no such item"
]
]
}
Code: Select all
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('192.168.104.61', username='ansible', password='1', port=22, allow_agent=False, look_for_keys=False)
stdin, stdout, stderr = client.exec_command(':put [/ip firewall filter get [find where comment "123456789101234567891012345678910"]]')
for line in stdout:
print(line.strip('\n'))
client.close()
Code: Select all
[Running] python -u "/home/aleksey/dev/mine/mikrotiks_vbox/tempCodeRunnerFile.py"
no such item
Code: Select all
uptime: 3h17m45s
version: 7.6 (stable)
build-time: Oct/17/2022 10:55:40
factory-software: 7.1
free-memory: 17.7MiB
total-memory: 96.0MiB
cpu: AMD
cpu-count: 1
cpu-frequency: 3399MHz
cpu-load: 0%
free-hdd-space: 186.6MiB
total-hdd-space: 204.2MiB
write-sect-since-reboot: 5480
write-sect-total: 5480
architecture-name: x86_64
board-name: x86
platform: MikroTik
So I don't know the root cause (mikrotik chr? ssh connection? network issue? ansible bug? AMD cpu bug?) how to fix it and any help is appreciated.