Ansible Terminal Expansion With Mikrotik
Mikrotik routers are, I’m finding, well suited to be used with Ansible as infrastructure as code.
I was recently working on a project where I was pulling “/ip firewall nat print without-paging terse”, but the returned output kept adding in \n (carriage returns) on the 81st position…*sigh*.
1 2 | "stdout": [ "0 comment=ReverseNAT chain=srcnat action=src-nat to-addresses=2.1.\n25.64 src-address=1.1.1.1 \n 1 comment=Mail_Reverse_NAT chain=srcnat action=src-nat to-addresses=1.1.1\n25.64 src-address=1.1.2.25 \n 2 X comment=VPN_Traffic chain=srcnat action=masquerade src-address=1.1.9.0/24 \ndst-address=1.1.2.0/24 \n 3 comment=VPN_Traffic chain=srcnat action=masquerade src-address=10.1.9.0/24 \n\n 4 |
It turns out that when connected via ssh, Mikrotik assumes a smaller window size on the terminal. The trick here is to edit the username used to connect with a special set of instructions:
1 | ansible_user=Tacos+cet512w |
+cet512w tells ansible the default terminal width is equal to 512 cols and enables “dumb” terminal mode. After this, all is right with the world 🙂
It took me about 2 hours to suss this out, then when I presented it to Jimmy he said “Oh yeah, that’s why I’ve got “+cet512w” in the user name, so really he gave me the fix. Another lesson hard earned hehehe.
If you are using ansible with Mikrotik and the routeros module is inserting carriage returns, give this a go. Oh, it also helps to have an Ansible Ninja on your team when you need a little help 😉