mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-22 03:53:59 -07:00
New module: platform agnostic way to manage local users on network devices (network/net_user.) (#25259)
* Add net_user platform agnostic module Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Integration test for net_user Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * modify eos_user module to support name param as alias to username Signed-off-by: Trishna Guha <trishnaguha17@gmail.com> * Test collection of users Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
parent
15104acc00
commit
f6a4803669
19 changed files with 334 additions and 13 deletions
|
@ -11,3 +11,4 @@
|
|||
- { role: net_system, when: "limit_to in ['*', 'net_system']" }
|
||||
- { role: net_banner, when: "limit_to in ['*', 'net_banner']" }
|
||||
- { role: net_command, when: "limit_to in ['*', 'net_command']" }
|
||||
- { role: net_user, when: "limit_to_in ['*', 'net_user']" }
|
||||
|
|
1
test/integration/targets/net_user/aliases
Normal file
1
test/integration/targets/net_user/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
network/ci
|
2
test/integration/targets/net_user/defaults/main.yaml
Normal file
2
test/integration/targets/net_user/defaults/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
16
test/integration/targets/net_user/tasks/cli.yaml
Normal file
16
test/integration/targets/net_user/tasks/cli.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
- name: collect all cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case
|
||||
include: "{{ test_case_to_run }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
2
test/integration/targets/net_user/tasks/main.yaml
Normal file
2
test/integration/targets/net_user/tasks/main.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- include: "{{ role_path }}/tests/eos/userprivilege.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos'
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- include: "{{ role_path }}/tests/nxos/userrole.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'nxos'
|
||||
|
||||
- include: "{{ role_path }}/tests/eos/userrole.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos'
|
6
test/integration/targets/net_user/tests/cli/users.yaml
Normal file
6
test/integration/targets/net_user/tests/cli/users.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
- include: "{{ role_path }}/tests/nxos/users.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'nxos'
|
||||
|
||||
- include: "{{ role_path }}/tests/eos/users.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos'
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
- name: Set user to privilege level 15
|
||||
net_user:
|
||||
name: netop
|
||||
privilege: 15
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["username netop privilege 15"]'
|
||||
|
||||
- name: tearDown
|
||||
net_user:
|
||||
purge: yes
|
||||
provider: "{{ cli }}"
|
22
test/integration/targets/net_user/tests/eos/userrole.yaml
Normal file
22
test/integration/targets/net_user/tests/eos/userrole.yaml
Normal file
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
- name: Set multiple users role
|
||||
net_user:
|
||||
collection:
|
||||
- name: netop
|
||||
- name: netend
|
||||
role: network-operator
|
||||
state: present
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["username netop role network-operator", "username netend role network-operator"]'
|
||||
|
||||
- name: tearDown
|
||||
net_user:
|
||||
purge: yes
|
||||
authorize: yes
|
||||
provider: "{{ cli }}"
|
23
test/integration/targets/net_user/tests/eos/users.yaml
Normal file
23
test/integration/targets/net_user/tests/eos/users.yaml
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
- name: Create user
|
||||
net_user:
|
||||
name: netop
|
||||
state: present
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["username netop"]'
|
||||
|
||||
- name: Purge users
|
||||
net_user:
|
||||
purge: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no username netop"]'
|
20
test/integration/targets/net_user/tests/nxos/userrole.yaml
Normal file
20
test/integration/targets/net_user/tests/nxos/userrole.yaml
Normal file
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
- name: Set multiple users role
|
||||
net_user:
|
||||
collection:
|
||||
- name: netop
|
||||
- name: netend
|
||||
role: network-operator
|
||||
state: present
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"role network-operator" in result.commands'
|
||||
|
||||
- name: tearDown
|
||||
net_user:
|
||||
purge: yes
|
||||
provider: "{{ cli }}"
|
23
test/integration/targets/net_user/tests/nxos/users.yaml
Normal file
23
test/integration/targets/net_user/tests/nxos/users.yaml
Normal file
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
- name: Create user
|
||||
net_user:
|
||||
name: netop
|
||||
state: present
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["username netop"]'
|
||||
|
||||
- name: Purge users
|
||||
net_user:
|
||||
purge: yes
|
||||
provider: "{{ cli }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- 'result.commands == ["no username netop"]'
|
Loading…
Add table
Add a link
Reference in a new issue