2017-07-06 18:27:12 +02:00
|
|
|
---
|
2018-01-08 13:28:47 +01:00
|
|
|
- debug: msg="START junos_user netconf/basic.yaml on connection={{ ansible_connection }}"
|
2017-07-06 18:27:12 +02:00
|
|
|
|
|
|
|
- name: setup - remove user
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: absent
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
|
|
|
|
- name: Create user
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: present
|
|
|
|
full_name: test_user
|
|
|
|
role: operator
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get running configuration
|
|
|
|
junos_rpc:
|
|
|
|
rpc: get-configuration
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
|
|
|
- "'<name>test_user</name>' in config.xml"
|
|
|
|
- "'<full-name>test_user</full-name>' in config.xml"
|
2017-08-02 10:41:10 +02:00
|
|
|
- "'<class>operator</class>' in config.xml"
|
2017-07-06 18:27:12 +02:00
|
|
|
|
|
|
|
- name: Create user again (idempotent)
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: present
|
|
|
|
full_name: test_user
|
|
|
|
role: operator
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == false"
|
|
|
|
|
|
|
|
- name: Deactivate user
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: present
|
|
|
|
full_name: test_user
|
|
|
|
role: operator
|
|
|
|
active: False
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get running configuration
|
|
|
|
junos_rpc:
|
|
|
|
rpc: get-configuration
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
|
|
|
- "'<user inactive=\"inactive\">' in config.xml"
|
|
|
|
- "'<name>test_user</name>' in config.xml"
|
|
|
|
|
|
|
|
- name: Activate user
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: present
|
|
|
|
full_name: test_user
|
|
|
|
role: operator
|
|
|
|
active: True
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get running configuration
|
|
|
|
junos_rpc:
|
|
|
|
rpc: get-configuration
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
|
|
|
- "'<name>test_user</name>' in config.xml"
|
|
|
|
- "'<full-name>test_user</full-name>' in config.xml"
|
2017-08-02 10:41:10 +02:00
|
|
|
- "'<class>operator</class>' in config.xml"
|
2017-07-06 18:27:12 +02:00
|
|
|
|
|
|
|
- name: Delete user
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: absent
|
|
|
|
full_name: test_user
|
|
|
|
role: operator
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get running configuration
|
|
|
|
junos_rpc:
|
|
|
|
rpc: get-configuration
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
|
|
|
- "'<name>test_user</name>' not in config.xml"
|
|
|
|
- "'<full-name>test_user</full-name>' not in config.xml"
|
|
|
|
|
|
|
|
- name: Delete user again (idempotent check)
|
|
|
|
junos_user:
|
|
|
|
name: test_user
|
|
|
|
state: absent
|
|
|
|
full_name: test_user
|
|
|
|
role: operator
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == false"
|
|
|
|
|
|
|
|
- name: Teardown list of users
|
|
|
|
junos_user:
|
2017-07-26 16:09:17 +02:00
|
|
|
aggregate:
|
2017-07-06 18:27:12 +02:00
|
|
|
- {name: test_user1, state: absent}
|
|
|
|
- {name: test_user2, state: absent}
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Create list of users
|
|
|
|
junos_user:
|
2017-07-26 16:09:17 +02:00
|
|
|
aggregate:
|
2017-07-06 18:27:12 +02:00
|
|
|
- {name: test_user1, full_name: test_user2, role: operator, state: present}
|
|
|
|
- {name: test_user2, full_name: test_user2, role: read-only, state: present}
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get running configuration
|
|
|
|
junos_rpc:
|
|
|
|
rpc: get-configuration
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
|
|
|
- "'<name>test_user1</name>' in config.xml"
|
|
|
|
- "'<name>test_user2</name>' in config.xml"
|
|
|
|
|
|
|
|
- name: Delete list of users
|
|
|
|
junos_user:
|
2017-07-26 16:09:17 +02:00
|
|
|
aggregate:
|
2017-07-06 18:27:12 +02:00
|
|
|
- {name: test_user1, full_name: test_user2, role: operator, state: absent}
|
|
|
|
- {name: test_user2, full_name: test_user2, role: read-only, state: absent}
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Get running configuration
|
|
|
|
junos_rpc:
|
|
|
|
rpc: get-configuration
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: config
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
|
|
|
- "'<name>test_user1</name>' not in config.xml"
|
|
|
|
- "'<name>test_user2</name>' not in config.xml"
|
2017-08-31 14:16:13 +02:00
|
|
|
|
|
|
|
- name: Create list of users
|
|
|
|
junos_user:
|
|
|
|
aggregate:
|
2019-05-15 17:09:10 +02:00
|
|
|
# NOTE(pabelanger): We noop our ansible-test user, as not to lose SSH access
|
|
|
|
- name: "{{ ansible_user|default('ansible') }}"
|
2017-08-31 14:16:13 +02:00
|
|
|
- {name: test_user1, full_name: test_user2, role: operator}
|
|
|
|
- {name: test_user2, full_name: test_user2, role: read-only}
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: Purge users except the users in aggregate
|
|
|
|
junos_user:
|
|
|
|
aggregate:
|
2019-05-15 17:09:10 +02:00
|
|
|
# NOTE(pabelanger): We noop our ansible-test user, as not to lose SSH access
|
|
|
|
- name: "{{ ansible_user|default('ansible') }}"
|
2017-08-31 14:16:13 +02:00
|
|
|
purge: True
|
|
|
|
provider: "{{ netconf }}"
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "result.changed == true"
|
2017-11-27 23:58:08 +01:00
|
|
|
- result.diff.prepared is search("\- *user test_user1")
|
|
|
|
- result.diff.prepared is search("\- *user test_user2")
|
2018-01-08 13:28:47 +01:00
|
|
|
|
|
|
|
- debug: msg="END junos_user netconf/basic.yaml on connection={{ ansible_connection }}"
|