Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ coverage:
patch: false
project:
default:
threshold: 0.3%
threshold: "0.3%"
4 changes: 1 addition & 3 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ authors:
license_file: LICENSE
name: utils
namespace: ansible
description:
Ansible Collection with utilities to ease the management, manipulation,
and validation of data within a playbook
description: Ansible Collection with utilities to ease the management, manipulation, and validation of data within a playbook
readme: README.md
repository: https://github.com/ansible-collections/ansible.utils
issues: https://github.com/ansible-collections/ansible.utils/issues
Expand Down
18 changes: 9 additions & 9 deletions tests/integration/targets/utils_cli_parse/tasks/argspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: "Validate argspec {{ parser }}"
- name: Validate argspec {{ parser }}
ansible.utils.cli_parse:
text: ""
parser:
Expand All @@ -9,13 +9,13 @@
register: argfail
ignore_errors: true

- name: "Check argspec fail {{ parser }}"
- name: Check argspec fail {{ parser }}
ansible.builtin.assert:
that: "{{ msg in argfail.errors }}"
vars:
msg: "parameters are mutually exclusive: command|template_path found in parser"

- name: "Validate argspec {{ parser }}"
- name: Validate argspec {{ parser }}
ansible.utils.cli_parse:
text: ""
command: ls
Expand All @@ -25,27 +25,27 @@
register: argfail
ignore_errors: true

- name: "Check argspec fail {{ parser }}"
- name: Check argspec fail {{ parser }}
ansible.builtin.assert:
that: "{{ msg in argfail.errors }}"
vars:
msg: "parameters are mutually exclusive: command|text"

- name: "Validate argspec {{ parser }}"
- name: Validate argspec {{ parser }}
ansible.utils.cli_parse:
parser:
name: ansible.netcommon.json
command: ""
register: argfail
ignore_errors: true

- name: "Check argspec fail {{ parser }}"
- name: Check argspec fail {{ parser }}
ansible.builtin.assert:
that: "{{ msg in argfail.errors }}"
vars:
msg: "one of the following is required: command, text"

- name: "Validate argspec {{ parser }}"
- name: Validate argspec {{ parser }}
ansible.utils.cli_parse:
text: ""
parser:
Expand All @@ -54,8 +54,8 @@
register: argfail
ignore_errors: true

- name: "Check arspec fail {{ parser }}"
- name: Check arspec fail {{ parser }}
ansible.builtin.assert:
that: "{{ msg in argfail.msg }}"
vars:
msg: "Parser name should be provided as a full name including collection"
msg: Parser name should be provided as a full name including collection
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "Run command and parse with textfsm {{ parser }}"
- name: Run command and parse with textfsm {{ parser }}
ansible.utils.cli_parse:
command: "ifconfig"
command: ifconfig
parser:
name: ansible.utils.textfsm
ansible.builtin.set_fact: myfact
register: ifconfig_out

- name: "Check parser output {{ parser }}"
- name: Check parser output {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "Run command and parse with ttp {{ parser }}"
- name: Run command and parse with ttp {{ parser }}
ansible.utils.cli_parse:
command: "df -h"
command: df -h
parser:
name: ansible.utils.ttp
ansible.builtin.set_fact: myfact
register: df_h_out

- name: "Check parser output {{ parser }}"
- name: Check parser output {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "Run command and parse with textfsm {{ parser }}"
- name: Run command and parse with textfsm {{ parser }}
ansible.utils.cli_parse:
command: "ifconfig"
command: ifconfig
parser:
name: ansible.utils.textfsm
ansible.builtin.set_fact: myfact
register: ifconfig_out

- name: "Check parser output {{ parser }}"
- name: Check parser output {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "Run command and parse with ttp {{ parser }}"
- name: Run command and parse with ttp {{ parser }}
ansible.utils.cli_parse:
command: "df -h"
command: df -h
parser:
name: ansible.utils.ttp
ansible.builtin.set_fact: myfact
register: df_h_out

- name: "Check parser output {{ parser }}"
- name: Check parser output {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
42 changes: 21 additions & 21 deletions tests/integration/targets/utils_cli_parse/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@
- name: Include argspec.yaml
ansible.builtin.include_tasks: argspec.yaml
vars:
parser: "({{ inventory_hostname }}/argspec)"
parser: ({{ inventory_hostname }}/argspec)

- name: Include nxos_json.yaml
ansible.builtin.include_tasks: "nxos_json.yaml"
ansible.builtin.include_tasks: nxos_json.yaml
vars:
parser: "(nxos/json)"
parser: (nxos/json)
tags:
- json

- name: Include nxos_textfsm.yaml
ansible.builtin.include_tasks: "nxos_textfsm.yaml"
ansible.builtin.include_tasks: nxos_textfsm.yaml
vars:
parser: "(nxos/textfsm)"
parser: (nxos/textfsm)
tags:
- textfsm

- name: Include nxos_ttp.yaml
ansible.builtin.include_tasks: "nxos_ttp.yaml"
ansible.builtin.include_tasks: nxos_ttp.yaml
vars:
parser: "(nxos/ttp)"
parser: (nxos/ttp)
tags:
- ttp

- name: Include nxos_xml.yaml
ansible.builtin.include_tasks: "nxos_xml.yaml"
ansible.builtin.include_tasks: nxos_xml.yaml
vars:
parser: "(nxos/xml)"
parser: (nxos/xml)
tags:
- xml

Expand All @@ -41,49 +41,49 @@
msg: "{{ os }}"

- name: Include centos_textfsm.yaml
ansible.builtin.include_tasks: "centos_textfsm.yaml"
ansible.builtin.include_tasks: centos_textfsm.yaml
vars:
parser: "(centos/textfsm)"
parser: (centos/textfsm)
when: os == 'centos'
tags:
- textfsm

- name: Include centos_ttp.yaml
ansible.builtin.include_tasks: "centos_ttp.yaml"
ansible.builtin.include_tasks: centos_ttp.yaml
vars:
parser: "(centos/ttp)"
parser: (centos/ttp)
when: os == 'centos'
tags:
- ttp

- name: Include fedora_textfsm.yaml
ansible.builtin.include_tasks: "fedora_textfsm.yaml"
ansible.builtin.include_tasks: fedora_textfsm.yaml
vars:
parser: "(fedora/textfsm)"
parser: (fedora/textfsm)
when: os == 'fedora'
tags:
- textfsm

- name: Include fedora_ttp.yaml
ansible.builtin.include_tasks: "fedora_ttp.yaml"
ansible.builtin.include_tasks: fedora_ttp.yaml
vars:
parser: "(fedora/ttp)"
parser: (fedora/ttp)
when: os == 'fedora'
tags:
- ttp

- name: Include ubuntu_textfsm.yaml
ansible.builtin.include_tasks: "ubuntu_textfsm.yaml"
ansible.builtin.include_tasks: ubuntu_textfsm.yaml
vars:
parser: "(ubuntu/textfsm)"
parser: (ubuntu/textfsm)
when: os == 'ubuntu'
tags:
- textfsm

- name: Include ubuntu_ttp.yaml
ansible.builtin.include_tasks: "ubuntu_ttp.yaml"
ansible.builtin.include_tasks: ubuntu_ttp.yaml
vars:
parser: "(ubuntu/ttp)"
parser: (ubuntu/ttp)
when: os == 'ubuntu'
tags:
- ttp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
ansible.builtin.set_fact:
nxos_json_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_interface_json_text.txt') }}"

- name: "Run command and parse with json {{ parser }}"
- name: Run command and parse with json {{ parser }}
ansible.utils.cli_parse:
text: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_interface_json_text.txt') }}"
parser:
name: ansible.utils.json
register: nxos_json_text

- name: "Confirm response {{ parser }}"
- name: Confirm response {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
ansible.builtin.set_fact:
nxos_textfsm_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_version_textfsm_parsed.json') | from_json }}"

- name: "Pass text and command {{ parser }}"
- name: Pass text and command {{ parser }}
ansible.utils.cli_parse:
text: "{{ lookup('ansible.builtin.file', '{{ role_path }}/files/nxos_show_version.txt') }}"
parser:
name: ansible.utils.textfsm
template_path: "{{ role_path }}/templates/nxos_show_version.textfsm"
register: nxos_textfsm_text

- name: "Confirm response {{ parser }}"
- name: Confirm response {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/targets/utils_cli_parse/tasks/nxos_ttp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ansible.builtin.set_fact:
nxos_ttp_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_interface_ttp_parsed.json') | from_json }}"

- name: "Pass text and template_path {{ parser }}"
- name: Pass text and template_path {{ parser }}
ansible.utils.cli_parse:
text: "{{ lookup('ansible.builtin.file', '{{ role_path }}/files/nxos_show_interface.txt') }}"
parser:
Expand All @@ -12,14 +12,14 @@
set_fact: POpqMQoJWTiDpEW
register: nxos_ttp_text

- name: "Confirm response {{ parser }}"
- name: Confirm response {{ parser }}
ansible.builtin.assert:
that:
- "{{ POpqMQoJWTiDpEW is defined }}"
- "{{ nxos_ttp_text['parsed'][0][0] | selectattr('interface', 'search', 'mgmt0') | list | length }}"
- "{{ nxos_ttp_text['parsed'] == nxos_ttp_text_parsed }}"

- name: "Pass text and custom variable {{ parser }}"
- name: Pass text and custom variable {{ parser }}
ansible.utils.cli_parse:
text: "{{ lookup('ansible.builtin.file', '{{ role_path }}/files/nxos_show_interface.txt') }}"
parser:
Expand All @@ -30,13 +30,13 @@
extra_var: some_text
register: nxos_ttp_vars

- name: "Confirm modified results {{ parser }}"
- name: Confirm modified results {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
- "{{ nxos_ttp_vars['parsed'][0][0][0]['var'] == 'some_text' }}"

- name: "Pass text and ttp_results modified {{ parser }}"
- name: Pass text and ttp_results modified {{ parser }}
ansible.utils.cli_parse:
text: "{{ lookup('ansible.builtin.file', '{{ role_path }}/files/nxos_show_interface.txt') }}"
parser:
Expand All @@ -47,7 +47,7 @@
format: yaml
register: nxos_ttp_results

- name: "Confirm modified results {{ parser }}"
- name: Confirm modified results {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/utils_cli_parse/tasks/nxos_xml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
ansible.builtin.set_fact:
nxos_xml_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_interface_xml_parsed.json') | from_json }}"

- name: "Pass text and parse with xml {{ parser }}"
- name: Pass text and parse with xml {{ parser }}
ansible.utils.cli_parse:
text: "{{ lookup('ansible.builtin.file', '{{ role_path }}/files/nxos_show_interface.xml') }}"
parser:
name: ansible.utils.xml
os: nxos
register: nxos_xml_text

- name: "Confirm response {{ parser }}"
- name: Confirm response {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "Run command and parse with textfsm {{ parser }}"
- name: Run command and parse with textfsm {{ parser }}
ansible.utils.cli_parse:
command: "ifconfig"
command: ifconfig
parser:
name: ansible.utils.textfsm
ansible.builtin.set_fact: myfact
register: ifconfig_out

- name: "Check parser output {{ parser }}"
- name: Check parser output {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: "Run command and parse with ttp {{ parser }}"
- name: Run command and parse with ttp {{ parser }}
ansible.utils.cli_parse:
command: "df -h"
command: df -h
parser:
name: ansible.utils.ttp
ansible.builtin.set_fact: myfact
register: df_h_out

- name: "Check parser output {{ parser }}"
- name: Check parser output {{ parser }}
ansible.builtin.assert:
that: "{{ item }}"
with_items:
Expand Down
Loading