From 5368e44f83caa6f61ccd9ec6f82dc5472742420a Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 27 Oct 2020 12:05:19 +0100 Subject: [PATCH] Improve docs (#2) --- README.md | 30 +++++++++++++++++++++++++++++- plugins/modules/api.py | 6 +++--- plugins/modules/command.py | 8 ++++---- plugins/modules/facts.py | 6 +++--- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1d6493e..5e79992 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ The collection supports the `network_cli` connection. See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for general detail on using collections. +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. + +### Connecting with `network_cli` + Example inventory `hosts` file: ```.ini @@ -42,7 +46,7 @@ Example playbook: ```.yaml --- -- name: RouterOS test +- name: RouterOS test with network_cli connection hosts: routers gather_facts: false tasks: @@ -61,6 +65,30 @@ Example playbook: msg: "First IP address: {{ ansible_net_all_ipv4_addresses[0] }}" ``` +### 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 + tasks: + - name: Get "ip address print" + community.routeros.api: + hostname: "{{ hostname }}" + password: "{{ password }}" + username: "{{ username }}" + path: "ip address" + ssl: true + register: print_path +``` + ## Contributing to this collection We're following the general Ansible contributor guidelines; see [Ansible Community Guide](https://docs.ansible.com/ansible/latest/community/index.html). diff --git a/plugins/modules/api.py b/plugins/modules/api.py index 9a62aba..ae22f05 100644 --- a/plugins/modules/api.py +++ b/plugins/modules/api.py @@ -113,7 +113,7 @@ EXAMPLES = ''' tasks: - name: Get "{{ path }} print" - community.network.api: + community.routeros.api: hostname: "{{ hostname }}" password: "{{ password }}" username: "{{ username }}" @@ -125,7 +125,7 @@ EXAMPLES = ''' msg: '{{ print_path }}' - name: Add ip address "{{ ip1 }}" and "{{ ip2 }}" - community.network.api: + community.routeros.api: hostname: "{{ hostname }}" password: "{{ password }}" username: "{{ username }}" @@ -141,7 +141,7 @@ EXAMPLES = ''' msg: '{{ addout }}' - name: Query for ".id" in "{{ path }} WHERE address == {{ ip2 }}" - community.network.api: + community.routeros.api: hostname: "{{ hostname }}" password: "{{ password }}" username: "{{ username }}" diff --git a/plugins/modules/command.py b/plugins/modules/command.py index 324b811..c180895 100644 --- a/plugins/modules/command.py +++ b/plugins/modules/command.py @@ -60,22 +60,22 @@ options: EXAMPLES = """ tasks: - name: Run command on remote devices - community.network.command: + community.routeros.command: commands: /system routerboard print - name: Run command and check to see if output contains routeros - community.network.command: + community.routeros.command: commands: /system resource print wait_for: result[0] contains MikroTik - name: Run multiple commands on remote nodes - community.network.command: + community.routeros.command: commands: - /system routerboard print - /system identity print - name: Run multiple commands and evaluate the output - community.network.command: + community.routeros.command: commands: - /system routerboard print - /interface ethernet print diff --git a/plugins/modules/facts.py b/plugins/modules/facts.py index 08cf374..4a4db7c 100644 --- a/plugins/modules/facts.py +++ b/plugins/modules/facts.py @@ -31,16 +31,16 @@ options: EXAMPLES = """ - name: Collect all facts from the device - community.network.facts: + community.routeros.facts: gather_subset: all - name: Collect only the config and default facts - community.network.facts: + community.routeros.facts: gather_subset: - config - name: Do not collect hardware facts - community.network.facts: + community.routeros.facts: gather_subset: - "!hardware" """