2022-08-05 14:03:38 +02:00
|
|
|
---
|
|
|
|
# Copyright (c) Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-03-09 10:11:07 +01:00
|
|
|
- name: list sessions
|
|
|
|
consul_session:
|
|
|
|
state: list
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
- "'sessions' in result"
|
|
|
|
|
|
|
|
- name: create a session
|
|
|
|
consul_session:
|
|
|
|
state: present
|
|
|
|
name: testsession
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
- result['name'] == 'testsession'
|
|
|
|
- "'session_id' in result"
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
session_id: "{{ result['session_id'] }}"
|
|
|
|
|
|
|
|
- name: list sessions after creation
|
|
|
|
consul_session:
|
|
|
|
state: list
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
session_count: "{{ result['sessions'] | length }}"
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
# selectattr not available on Jinja 2.2 provided by CentOS 6
|
|
|
|
# hence the two following tasks (set_fact/assert) are used
|
|
|
|
# - (result['sessions'] | selectattr('ID', 'match', '^' ~ session_id ~ '$') | first)['Name'] == 'testsession'
|
|
|
|
|
|
|
|
- name: search created session
|
|
|
|
set_fact:
|
2023-03-06 23:02:24 +01:00
|
|
|
test_session_found: true
|
2020-03-09 10:11:07 +01:00
|
|
|
loop: "{{ result['sessions'] }}"
|
|
|
|
when: "item.get('ID') == session_id and item.get('Name') == 'testsession'"
|
|
|
|
|
|
|
|
- name: ensure session was created
|
|
|
|
assert:
|
|
|
|
that:
|
2023-07-07 08:09:28 +02:00
|
|
|
- test_session_found|default(false)
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- name: fetch info about a session
|
|
|
|
consul_session:
|
|
|
|
state: info
|
|
|
|
id: '{{ session_id }}'
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
|
|
|
|
- name: ensure 'id' parameter is required when state=info
|
|
|
|
consul_session:
|
|
|
|
state: info
|
|
|
|
name: test
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
2023-03-06 23:02:24 +01:00
|
|
|
ignore_errors: true
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
|
|
|
|
- name: ensure unknown scheme fails
|
|
|
|
consul_session:
|
|
|
|
state: info
|
|
|
|
id: '{{ session_id }}'
|
|
|
|
scheme: non_existent
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
2023-03-06 23:02:24 +01:00
|
|
|
ignore_errors: true
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
|
2022-02-21 21:14:45 +01:00
|
|
|
- name: ensure SSL certificate is checked
|
|
|
|
consul_session:
|
|
|
|
state: info
|
|
|
|
id: '{{ session_id }}'
|
|
|
|
port: 8501
|
|
|
|
scheme: https
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2022-02-21 21:14:45 +01:00
|
|
|
register: result
|
2023-03-06 23:02:24 +01:00
|
|
|
ignore_errors: true
|
2022-02-21 21:14:45 +01:00
|
|
|
|
|
|
|
- name: previous task should fail since certificate is not known
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
- "'certificate verify failed' in result.msg"
|
|
|
|
|
|
|
|
- name: ensure SSL certificate isn't checked when validate_certs is disabled
|
|
|
|
consul_session:
|
|
|
|
state: info
|
|
|
|
id: '{{ session_id }}'
|
|
|
|
port: 8501
|
|
|
|
scheme: https
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2023-03-06 23:02:24 +01:00
|
|
|
validate_certs: false
|
2022-02-21 21:14:45 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: previous task should succeed since certificate isn't checked
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
|
|
|
|
- name: ensure a secure connection is possible
|
|
|
|
consul_session:
|
|
|
|
state: info
|
|
|
|
id: '{{ session_id }}'
|
|
|
|
port: 8501
|
|
|
|
scheme: https
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2022-02-21 21:14:45 +01:00
|
|
|
environment:
|
|
|
|
REQUESTS_CA_BUNDLE: '{{ remote_dir }}/cert.pem'
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
- name: delete a session
|
|
|
|
consul_session:
|
|
|
|
state: absent
|
|
|
|
id: '{{ session_id }}'
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
|
|
|
|
- name: list sessions after deletion
|
|
|
|
consul_session:
|
|
|
|
state: list
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2020-03-09 10:11:07 +01:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
# selectattr and equalto not available on Jinja 2.2 provided by CentOS 6
|
|
|
|
# hence the two following tasks (command/assert) are used
|
|
|
|
# - (result['sessions'] | selectattr('ID', 'equalto', session_id) | list | length) == 0
|
|
|
|
|
|
|
|
- name: search deleted session
|
|
|
|
command: echo 'session found'
|
|
|
|
loop: "{{ result['sessions'] }}"
|
|
|
|
when: "item.get('ID') == session_id and item.get('Name') == 'testsession'"
|
|
|
|
register: search_deleted
|
|
|
|
|
|
|
|
- name: ensure session was deleted
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- search_deleted is skipped # each iteration is skipped
|
|
|
|
- search_deleted is not changed # and then unchanged
|
2022-07-31 13:17:43 +02:00
|
|
|
|
|
|
|
- name: ensure session can be created with a ttl
|
|
|
|
consul_session:
|
|
|
|
state: present
|
|
|
|
name: session-with-ttl
|
|
|
|
ttl: 180 # sec
|
2023-07-07 08:09:28 +02:00
|
|
|
token: "{{ consul_management_token }}"
|
2022-07-31 13:17:43 +02:00
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is changed
|
|
|
|
- result['ttl'] == 180
|