Skip to content

Commit

Permalink
Enable ansible-lint for utils and fix ansible-lint issue (#278)
Browse files Browse the repository at this point in the history
* Fix ansible-lint issue for utils

* fix ansible-lint

* Fix ansible-lint

* Fix ansible-lint

* Fix integration test
  • Loading branch information
ashwini-mhatre authored May 19, 2023
1 parent c0e0946 commit 6adf947
Show file tree
Hide file tree
Showing 51 changed files with 206 additions and 204 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on: # yamllint disable-line rule:truthy
- cron: '0 0 * * *'

jobs:
ansible-lint:
uses: ansible-network/github_actions/.github/workflows/ansible-lint.yml@main
changelog:
uses: ansible-network/github_actions/.github/workflows/changelog.yml@main
integration:
Expand Down
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
dictionaryDefinitions:
- name: words
path: .config/dictionary.txt
Expand Down
8 changes: 4 additions & 4 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 @@ -15,7 +15,7 @@
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 @@ -31,7 +31,7 @@
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
Expand All @@ -45,7 +45,7 @@
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 Down
2 changes: 1 addition & 1 deletion tests/integration/targets/utils_cli_parse/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
tags:
- xml

- name: debug os
- name: Debug os
ansible.builtin.debug:
msg: "{{ os }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set fact
- name: Set fact
ansible.builtin.set_fact:
nxos_textfsm_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_version_textfsm_parsed.json') | from_json }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set fact
- name: Set fact
ansible.builtin.set_fact:
nxos_ttp_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_interface_ttp_parsed.json') | from_json }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set fact
- name: Set fact
ansible.builtin.set_fact:
nxos_xml_text_parsed: "{{ lookup('ansible.builtin.file', '{{ role_path }}/output/nxos_show_interface_xml_parsed.json') | from_json }}"

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/utils_from_xml/tasks/simple.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ansible.builtin.set_fact:
data: '<netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">'

- name: validate input xml
- name: Validate input xml
ansible.builtin.set_fact:
_result: "{{ data|ansible.utils.from_xml() }}"
ignore_errors: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@

- name: Retrieve the value of each path from vars
ansible.builtin.debug:
msg: "The value of path {{ path }} in vars is {{ value }}"
msg: "The value of path {{ path }} in vars is {{ lookup('ansible.utils.get_path', hostvars[inventory_hostname], path) }}"
loop: "{{ paths.keys()|list }}"
loop_control:
label: "{{ item }}"
vars:
path: "{{ item }}"
value: "{{ lookup('ansible.utils.get_path', hostvars[inventory_hostname], item) }}"
loop_var: path
# TASK [Get the paths for the object] *******************************
# ok: [nxos101] => changed=false
# ansible_facts:
Expand Down
26 changes: 14 additions & 12 deletions tests/integration/targets/utils_index_of/tasks/examples_lookup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,25 +218,27 @@
index: 3
index: 3

- name: Set fact
ansible.builtin.set_fact:
int_idx: |
"{{ lookup('ansible.utils.index_of',
data.interfaces.interface,
'eq', 'loopback1111', 'name') }}"
- name: Set fact
ansible.builtin.set_fact:
subint_idx: |
"{{ lookup('ansible.utils.index_of',
data.interfaces.interface[int_idx|int].subinterfaces.subinterface,
'eq', 10, 'index') }}"
- name: Find the description of loopback111, subinterface index 10
ansible.builtin.debug:
msg: |-
{{ data.interfaces.interface[int_idx|int]
.subinterfaces.subinterface[subint_idx|int]
.config.description }}
vars:
# the values to search for
int_name: loopback1111
sub_index: 10
# retrieve the index in each nested list
int_idx: |
{{ lookup('ansible.utils.index_of',
data.interfaces.interface,
'eq', int_name, 'name') }}
subint_idx: |
{{ lookup('ansible.utils.index_of',
data.interfaces.interface[int_idx|int].subinterfaces.subinterface,
'eq', sub_index, 'index') }}

# TASK [Find the description of loopback111, subinterface index 10] ************
# ok: [sw01] =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
---
- name: cidr_merge with merge action
- name: Cidr_merge with merge action
ansible.builtin.set_fact:
value:
- 192.168.0.0/17
- 192.168.128.0/17
- 192.168.128.1

- name: cidr_merge with merge action
- name: Cidr_merge with merge action
ansible.builtin.set_fact:
result1: "{{ value|ansible.utils.cidr_merge }}"

- name: Assert result for cidr_merge
ansible.builtin.assert:
that: "{{ result1 == cidr_result1 }}"

- name: cidr_merge with span action
- name: Cidr_merge with span action
ansible.builtin.set_fact:
value:
- 192.168.1.1
- 192.168.1.2
- 192.168.1.3
- 192.168.1.4

- name: cidr_merge with span action
- name: Cidr_merge with span action
ansible.builtin.set_fact:
result2: "{{ value|ansible.utils.cidr_merge('span') }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: hwaddr filter test1
- name: Hwaddr filter test1
ansible.builtin.set_fact:
result1: "{{ '1a:2b:3c:4d:5e:6f'|ansible.utils.hwaddr }}"

- name: Assert result for hwaddr.
ansible.builtin.assert:
that: "{{ result1 == '1a:2b:3c:4d:5e:6f' }}"

- name: hwaddr filter test2
- name: Hwaddr filter test2
ansible.builtin.set_fact:
result1: "{{ '1a:2b:3c:4d:5e:6f'|ansible.utils.hwaddr('cisco') }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: ip4_hex without delimiter
- name: Ip4_hex without delimiter
ansible.builtin.set_fact:
result1: "{{ '192.168.1.5'|ansible.utils.ip4_hex }}"

- name: Assert result for ip4_hex.
ansible.builtin.assert:
that: "{{ result1 == 'c0a80105' }}"

- name: ip4_hex with delimiter
- name: Ip4_hex with delimiter
ansible.builtin.set_fact:
result1: "{{ '192.168.1.5'|ansible.utils.ip4_hex(':') }}"

Expand Down
16 changes: 8 additions & 8 deletions tests/integration/targets/utils_ipaddr_filter/tasks/ipaddr.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set ipaddress list
- name: Set ipaddress list
ansible.builtin.set_fact:
value:
- 192.24.2.1
Expand All @@ -10,47 +10,47 @@
- "42540766412265424405338506004571095040/64"
- true

- name: ipaddr filter with empty string query
- name: Ipaddr filter with empty string query
ansible.builtin.set_fact:
result1: "{{ value|ansible.utils.ipaddr }}"

- name: Assert result for ipaddr.
ansible.builtin.assert:
that: "{{ result1 == ipaddr_result1 }}"

- name: ipaddr filter with host string query
- name: Ipaddr filter with host string query
ansible.builtin.set_fact:
result2: "{{ value|ansible.utils.ipaddr('host') }}"

- name: Assert result for ipaddr host query
ansible.builtin.assert:
that: "{{ result2 == ipaddr_result2 }}"

- name: ipaddr filter with public network query
- name: Ipaddr filter with public network query
ansible.builtin.set_fact:
result3: "{{ value|ansible.utils.ipaddr('public') }}"

- name: Assert result for ipaddr public network query
ansible.builtin.assert:
that: "{{ result3== ipaddr_result3 }}"

- name: ipaddr filter with network query
- name: Ipaddr filter with network query
ansible.builtin.set_fact:
result4: "{{ value|ansible.utils.ipaddr('net') }}"

- name: Assert result for ipaddr network query
ansible.builtin.assert:
that: "{{ result4 == ipaddr_result4 }}"

- name: ipaddr filter with network/prefix query
- name: Ipaddr filter with network/prefix query
ansible.builtin.set_fact:
result5: "{{ '192.168.0.0/23' | ansible.utils.ipaddr('network/prefix') }}"

- name: Assert result for ipaddr filter with network/prefix query
ansible.builtin.assert:
that: "{{ result5 == '192.168.0.0/23' }}"

- name: ipaddr filter with chained filters
- name: Ipaddr filter with chained filters
ansible.builtin.set_fact:
result6: "{{ '192.168.255.0' | ansible.utils.ipaddr('network') | ansible.utils.ipmath(123) }}"

Expand All @@ -62,7 +62,7 @@
ansible.builtin.debug:
msg: "Test int input for ipaddr filter"

- name: set fact 1
- name: Set fact 1
ansible.builtin.set_fact:
ip1: "172.20.0.1"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: convert address to subnet using ipsubnet
- name: Convert address to subnet using ipsubnet
ansible.builtin.set_fact:
result1: "{{ address | ansible.utils.ipsubnet }}"

- name: Assert result for ipsubnet.
ansible.builtin.assert:
that: "{{ result1 == '192.168.144.5/32' }}"

- name: check if given value is subnet
- name: Check if given value is subnet
ansible.builtin.set_fact:
result2: "{{ subnet | ansible.utils.ipsubnet }}"

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/targets/utils_ipaddr_filter/tasks/ipv4.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set ipaddress list
- name: Set ipaddress list
ansible.builtin.set_fact:
value:
- 192.24.2.1
Expand All @@ -10,15 +10,15 @@
- "42540766412265424405338506004571095040/64"
- true

- name: ipv4 filter
- name: Ipv4 filter
ansible.builtin.set_fact:
result1: "{{ value|ansible.utils.ipv4 }}"

- name: Assert result for ipv4.
ansible.builtin.assert:
that: "{{ result1 == result1_val }}"

- name: convert ipv4 to ipv6 filter
- name: Convert ipv4 to ipv6 filter
ansible.builtin.set_fact:
result2: "{{ value|ansible.utils.ipv4('ipv6') }}"

Expand All @@ -34,7 +34,7 @@
ansible.builtin.assert:
that: "{{ result3 == result3_val }}"

- name: ipv4 filter with single value
- name: Ipv4 filter with single value
ansible.builtin.set_fact:
result4: "{{ '192.24.2.1' | ansible.utils.ipv4('ipv6') }}"

Expand Down
8 changes: 4 additions & 4 deletions tests/integration/targets/utils_ipaddr_filter/tasks/ipv6.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set ipaddress list
- name: Set ipaddress list
ansible.builtin.set_fact:
value:
- 192.24.2.1
Expand All @@ -10,15 +10,15 @@
- fe80::100/10
- true

- name: ipv6 filter
- name: Ipv6 filter
ansible.builtin.set_fact:
result1: "{{ value|ansible.utils.ipv6 }}"

- name: Assert result for ipv6.
ansible.builtin.assert:
that: "{{ result1 == ipv6_result1 }}"

- name: convert ipv6 to ipv4 filter
- name: Convert ipv6 to ipv4 filter
ansible.builtin.set_fact:
result2: "{{ value|ansible.utils.ipv6('ipv4') }}"

Expand All @@ -34,7 +34,7 @@
ansible.builtin.assert:
that: "{{ result3 == ipv6_result3 }}"

- name: ipv6 filter with single value
- name: Ipv6 filter with single value
ansible.builtin.set_fact:
result4: "{{ '::ffff:192.168.32.0/120' | ansible.utils.ipv6('ipv4') }}"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: set ipaddress list
- name: Set ipaddress list
ansible.builtin.set_fact:
value:
- 192.24.2.1
Expand All @@ -10,15 +10,15 @@
- "42540766412265424405338506004571095040/64"
- true

- name: ipwrap filter
- name: Ipwrap filter
ansible.builtin.set_fact:
result1: "{{ value|ansible.utils.ipwrap }}"

- name: Assert result for ipwrap.
ansible.builtin.assert:
that: "{{ result1 == ipwrap_result1 }}"

- name: ipwrap filter with single value
- name: Ipwrap filter with single value
ansible.builtin.set_fact:
result4: "{{ 'fe80::100/10' | ansible.utils.ipwrap }}"

Expand Down
Loading

0 comments on commit 6adf947

Please sign in to comment.