ansible-collections.communi.../README.md

174 lines
6.5 KiB
Markdown
Raw Normal View History

<!--
Copyright (c) Ansible Project
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later
-->
2020-10-26 14:33:47 +01:00
# Community RouterOS Collection
[![CI](https://github.com/ansible-collections/community.routeros/workflows/CI/badge.svg?event=push)](https://github.com/ansible-collections/community.routeros/actions) [![Codecov](https://img.shields.io/codecov/c/github/ansible-collections/community.routeros)](https://codecov.io/gh/ansible-collections/community.routeros)
2020-10-26 07:28:29 +00:00
2020-10-26 15:17:35 +01:00
Provides modules for [Ansible](https://www.ansible.com/community) to manage [MikroTik RouterOS](http://www.mikrotik-routeros.net/routeros.aspx) instances.
2020-10-26 07:28:29 +00:00
2021-07-07 13:29:49 +02:00
You can find [documentation for the modules and plugins in this collection here](https://docs.ansible.com/ansible/devel/collections/community/routeros/).
2020-10-26 07:28:29 +00:00
## Tested with Ansible
2022-03-29 06:16:43 +02:00
Tested with the current Ansible 2.9, ansible-base 2.10, ansible-core 2.11, ansible-core 2.12 and ansible-core 2.13 releases and the current development version of ansible-core. Ansible versions before 2.9.10 are not supported.
2020-10-26 07:28:29 +00:00
## External requirements
2020-10-26 15:17:35 +01:00
The exact requirements for every module are listed in the module documentation.
2020-10-26 07:28:29 +00:00
### Supported connections
2020-10-26 15:26:18 +01:00
The collection supports the `network_cli` connection.
2020-10-26 07:28:29 +00:00
### Edge cases
Please note that `community.routeros.api` module does **not** support Windows jump hosts!
2020-10-26 07:28:29 +00:00
## Included content
2020-10-26 15:26:18 +01:00
- `community.routeros.api`
2022-05-24 22:51:27 +02:00
- `community.routeros.api_facts`
- `community.routeros.api_find_and_modify`
2020-10-26 15:26:18 +01:00
- `community.routeros.command`
- `community.routeros.facts`
2020-10-26 07:28:29 +00:00
2021-07-07 13:29:49 +02:00
You can find [documentation for the modules and plugins in this collection here](https://docs.ansible.com/ansible/devel/collections/community/routeros/).
2020-10-26 07:28:29 +00:00
## Using this collection
2020-10-26 20:24:36 +01:00
See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for general detail on using collections.
2020-10-27 12:05:19 +01:00
There are two approaches for using this collection. The `command` and `facts` modules use the `network_cli` connection and connect with SSH. The `api` module connects with the HTTP/HTTPS API.
### Prerequisites
The terminal-based modules in this collection (`community.routeros.command` and `community.routeros.facts`) do not support arbitrary symbols in router's identity. If you are having trouble connecting to your device, please make sure that your MikroTik's identity contains only alphanumeric characters and dashes. Also, the `community.routeros.command` module does not support nesting commands and expects every command to start with a forward slash (`/`). Running the following command will produce an error.
```yaml
- community.routeros.command:
commands:
- /ip
- print
```
2020-10-27 12:05:19 +01:00
### Connecting with `network_cli`
2020-10-26 20:24:36 +01:00
Example inventory `hosts` file:
```.ini
[routers]
router ansible_host=192.168.1.1
[routers:vars]
ansible_connection=ansible.netcommon.network_cli
ansible_network_os=community.routeros.routeros
ansible_user=admin
ansible_ssh_pass=test1234
```
Example playbook:
```.yaml
---
2020-10-27 12:05:19 +01:00
- name: RouterOS test with network_cli connection
2020-10-26 20:24:36 +01:00
hosts: routers
gather_facts: false
tasks:
2022-05-24 22:51:27 +02:00
- name: Run a command
community.routeros.command:
commands:
- /system resource print
register: system_resource_print
- name: Print its output
ansible.builtin.debug:
var: system_resource_print.stdout_lines
- name: Retrieve facts
community.routeros.facts:
- ansible.builtin.debug:
msg: "First IP address: {{ ansible_net_all_ipv4_addresses[0] }}"
2020-10-26 20:24:36 +01:00
```
2020-10-26 07:28:29 +00:00
2020-10-27 12:05:19 +01:00
### Connecting with HTTP/HTTPS API
Example playbook:
```.yaml
---
- name: RouterOS test with API
hosts: localhost
gather_facts: no
vars:
hostname: 192.168.1.1
username: admin
password: test1234
2022-05-24 22:51:27 +02:00
module_defaults:
group/community.routeros.api:
hostname: "{{ hostname }}"
password: "{{ password }}"
username: "{{ username }}"
tls: true
validate_certs: true
validate_cert_hostname: true
ca_path: /path/to/ca-certificate.pem
2020-10-27 12:05:19 +01:00
tasks:
- name: Get "ip address print"
community.routeros.api:
2022-05-24 22:51:27 +02:00
path: ip address
2020-10-27 12:05:19 +01:00
register: print_path
2022-05-24 22:51:27 +02:00
- name: Print the result
ansible.builtin.debug:
var: print_path.msg
- name: Change IP address to 192.168.1.1 for interface bridge
community.routeros.api_find_and_modify:
path: ip address
find:
interface: bridge
values:
address: "192.168.1.1/24"
- name: Retrieve facts
community.routeros.api_facts:
- ansible.builtin.debug:
msg: "First IP address: {{ ansible_net_all_ipv4_addresses[0] }}"
2020-10-27 12:05:19 +01:00
```
2020-10-26 07:28:29 +00:00
## Contributing to this collection
2020-10-26 15:17:35 +01:00
We're following the general Ansible contributor guidelines; see [Ansible Community Guide](https://docs.ansible.com/ansible/latest/community/index.html).
If you want to clone this repositority (or a fork of it) to improve it, you can proceed as follows:
1. Create a directory `ansible_collections/community`;
2. In there, checkout this repository (or a fork) as `routeros`;
3. Add the directory containing `ansible_collections` to your [ANSIBLE_COLLECTIONS_PATH](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths).
2020-10-26 07:28:29 +00:00
2020-10-26 15:17:35 +01:00
See [Ansible's dev guide](https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html#contributing-to-collections) for more information.
2020-10-26 07:28:29 +00:00
## Release notes
2020-10-26 15:17:35 +01:00
See the [changelog](https://github.com/ansible-collections/community.routeros/blob/main/CHANGELOG.rst).
2020-10-26 07:28:29 +00:00
## Roadmap
2020-10-26 15:17:35 +01:00
We plan to regularly release minor and patch versions, whenever new features are added or bugs fixed. Our collection follows [semantic versioning](https://semver.org/), so breaking changes will only happen in major releases.
2020-10-26 07:28:29 +00:00
## More information
- [Ansible Collection overview](https://github.com/ansible-collections/overview)
- [Ansible User guide](https://docs.ansible.com/ansible/latest/user_guide/index.html)
- [Ansible Developer guide](https://docs.ansible.com/ansible/latest/dev_guide/index.html)
- [Ansible Collections Checklist](https://github.com/ansible-collections/overview/blob/master/collection_requirements.rst)
- [Ansible Community code of conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html)
- [The Bullhorn (the Ansible Contributor newsletter)](https://us19.campaign-archive.com/home/?u=56d874e027110e35dea0e03c1&id=d6635f5420)
- [Changes impacting Contributors](https://github.com/ansible-collections/overview/issues/45)
## Licensing
GNU General Public License v3.0 or later.
2020-10-26 14:33:47 +01:00
See [COPYING](https://www.gnu.org/licenses/gpl-3.0.txt) to see the full text.