{"id":5680,"date":"2024-02-19T19:29:00","date_gmt":"2024-02-20T01:29:00","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5680"},"modified":"2024-02-19T16:30:36","modified_gmt":"2024-02-19T22:30:36","slug":"setup-ansible-and-mikrotik-routeros","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/setup-ansible-and-mikrotik-routeros\/","title":{"rendered":"Setup Ansible and Mikrotik RouterOS"},"content":{"rendered":"\n<p><a href=\"https:\/\/docs.ansible.com\/ansible\/devel\/collections\/community\/routeros\/\">https:\/\/docs.ansible.com\/ansible\/devel\/collections\/community\/routeros\/<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/ansible-collections\/community.routeros\">https:\/\/github.com\/ansible-collections\/community.routeros<\/a><\/p>\n\n\n\n<p>Install the RouterOS collection.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ansible-galaxy collection install community.routeros<\/code><\/pre>\n\n\n\n<p>Create inventory<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi inventory.ini<\/pre>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">[routers]\nmikrotik ansible_host=192.168.88.1\n\n[routers:vars]\nansible_connection=ansible.netcommon.network_cli\nansible_network_os=community.routeros.routeros\nansible_user=admin\nansible_ssh_pass=\nansible_ssh_port=22<\/code><\/pre>\n\n\n\n<p>If you are using a custom SSH port, be sure that ansible-pylibssh is installed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install ansible-pylibssh<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Simple Playbook<\/h2>\n\n\n\n<p>This simple playbook will print the system resources.  Playbook is taken from <a href=\"https:\/\/docs.ansible.com\/ansible\/devel\/collections\/community\/routeros\/docsite\/ssh-guide.html\">here<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-dark-gray-background-color has-background\"><code class=\"\">---\n- name: RouterOS test with network_cli connection\n  hosts: routers\n  gather_facts: false\n  tasks:\n\n  - name: Gather system resources\n    community.routeros.command:\n      commands:\n        - \/system resource print\n    register: system_resource_print\n\n  - name: Show system resources\n    debug:\n      var: system_resource_print.stdout_lines\n\n  - name: Gather facts\n    community.routeros.facts:\n\n  - name: Show a fact\n    debug:\n      msg: \"First IP address: {{ ansible_net_all_ipv4_addresses[0] }}\"\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/docs.ansible.com\/ansible\/devel\/collections\/community\/routeros\/ https:\/\/github.com\/ansible-collections\/community.routeros Install the RouterOS collection. ansible-galaxy collection install community.routeros Create inventory vi inventory.ini If you are using a custom SSH port, be sure that ansible-pylibssh is installed. pip install ansible-pylibssh Simple Playbook This simple playbook will print the system &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/setup-ansible-and-mikrotik-routeros\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1646,1647,452],"tags":[1193,244,301,388],"class_list":["post-5680","post","type-post","status-publish","format-standard","hentry","category-ansible","category-automation","category-mikrotik","tag-ansible","tag-automation","tag-mikrotik","tag-routeros"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5680"}],"version-history":[{"count":4,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5680\/revisions"}],"predecessor-version":[{"id":5686,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5680\/revisions\/5686"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}