mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-08 15:14:20 -07:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
3
tests/integration/targets/consul/aliases
Normal file
3
tests/integration/targets/consul/aliases
Normal file
|
@ -0,0 +1,3 @@
|
|||
shippable/posix/group2
|
||||
destructive
|
||||
skip/aix
|
3
tests/integration/targets/consul/meta/main.yml
Normal file
3
tests/integration/targets/consul/meta/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
dependencies:
|
||||
- setup_openssl
|
162
tests/integration/targets/consul/tasks/consul_session.yml
Normal file
162
tests/integration/targets/consul/tasks/consul_session.yml
Normal file
|
@ -0,0 +1,162 @@
|
|||
- name: list sessions
|
||||
consul_session:
|
||||
state: list
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- "'sessions' in result"
|
||||
|
||||
- name: create a session
|
||||
consul_session:
|
||||
state: present
|
||||
name: testsession
|
||||
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
|
||||
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:
|
||||
test_session_found: True
|
||||
loop: "{{ result['sessions'] }}"
|
||||
when: "item.get('ID') == session_id and item.get('Name') == 'testsession'"
|
||||
|
||||
- name: ensure session was created
|
||||
assert:
|
||||
that:
|
||||
- test_session_found|default(False)
|
||||
|
||||
- name: fetch info about a session
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: ensure 'id' parameter is required when state=info
|
||||
consul_session:
|
||||
state: info
|
||||
name: test
|
||||
register: result
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
- name: ensure unknown scheme fails
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
scheme: non_existent
|
||||
register: result
|
||||
ignore_errors: True
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
- when: pyopenssl_version.stdout is version('0.15', '>=')
|
||||
block:
|
||||
- name: ensure SSL certificate is checked
|
||||
consul_session:
|
||||
state: info
|
||||
id: '{{ session_id }}'
|
||||
port: 8501
|
||||
scheme: https
|
||||
register: result
|
||||
ignore_errors: True
|
||||
|
||||
- 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
|
||||
validate_certs: False
|
||||
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
|
||||
environment:
|
||||
REQUESTS_CA_BUNDLE: '{{ remote_dir }}/cert.pem'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: delete a session
|
||||
consul_session:
|
||||
state: absent
|
||||
id: '{{ session_id }}'
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: list sessions after deletion
|
||||
consul_session:
|
||||
state: list
|
||||
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
|
82
tests/integration/targets/consul/tasks/main.yml
Normal file
82
tests/integration/targets/consul/tasks/main.yml
Normal file
|
@ -0,0 +1,82 @@
|
|||
- name: Install Consul and test
|
||||
vars:
|
||||
consul_version: 1.5.0
|
||||
consul_uri: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/consul/consul_{{ consul_version }}_{{ ansible_system | lower }}_{{ consul_arch }}.zip
|
||||
consul_cmd: '{{ output_dir }}/consul'
|
||||
block:
|
||||
- name: register pyOpenSSL version
|
||||
command: '{{ ansible_python_interpreter }} -c ''import OpenSSL; print(OpenSSL.__version__)'''
|
||||
register: pyopenssl_version
|
||||
- name: Install requests<2.20 (CentOS/RHEL 6)
|
||||
pip:
|
||||
name: requests<2.20
|
||||
register: result
|
||||
until: result is success
|
||||
when: ansible_distribution_file_variety|default() == 'RedHat' and ansible_distribution_major_version is version('6', '<=')
|
||||
- name: Install python-consul
|
||||
pip:
|
||||
name: python-consul
|
||||
register: result
|
||||
until: result is success
|
||||
- when: pyopenssl_version.stdout is version('0.15', '>=')
|
||||
block:
|
||||
- name: Generate privatekey
|
||||
community.crypto.openssl_privatekey:
|
||||
path: '{{ output_dir }}/privatekey.pem'
|
||||
- name: Generate CSR
|
||||
community.crypto.openssl_csr:
|
||||
path: '{{ output_dir }}/csr.csr'
|
||||
privatekey_path: '{{ output_dir }}/privatekey.pem'
|
||||
subject:
|
||||
commonName: localhost
|
||||
- name: Generate selfsigned certificate
|
||||
register: selfsigned_certificate
|
||||
community.crypto.openssl_certificate:
|
||||
path: '{{ output_dir }}/cert.pem'
|
||||
csr_path: '{{ output_dir }}/csr.csr'
|
||||
privatekey_path: '{{ output_dir }}/privatekey.pem'
|
||||
provider: selfsigned
|
||||
selfsigned_digest: sha256
|
||||
- name: Install unzip
|
||||
package:
|
||||
name: unzip
|
||||
register: result
|
||||
until: result is success
|
||||
when: ansible_distribution != "MacOSX"
|
||||
- assert:
|
||||
that: ansible_architecture in ['i386', 'x86_64', 'amd64']
|
||||
- set_fact:
|
||||
consul_arch: '386'
|
||||
when: ansible_architecture == 'i386'
|
||||
- set_fact:
|
||||
consul_arch: amd64
|
||||
when: ansible_architecture in ['x86_64', 'amd64']
|
||||
- name: Download consul binary
|
||||
unarchive:
|
||||
src: '{{ consul_uri }}'
|
||||
dest: '{{ output_dir }}'
|
||||
remote_src: true
|
||||
register: result
|
||||
until: result is success
|
||||
- vars:
|
||||
remote_dir: '{{ echo_output_dir.stdout }}'
|
||||
block:
|
||||
- command: echo {{ output_dir }}
|
||||
register: echo_output_dir
|
||||
- name: Create configuration file
|
||||
template:
|
||||
src: consul_config.hcl.j2
|
||||
dest: '{{ output_dir }}/consul_config.hcl'
|
||||
- name: Start Consul (dev mode enabled)
|
||||
shell: nohup {{ consul_cmd }} agent -dev -config-file {{ output_dir }}/consul_config.hcl </dev/null >/dev/null 2>&1 &
|
||||
- name: Create some data
|
||||
command: '{{ consul_cmd }} kv put data/value{{ item }} foo{{ item }}'
|
||||
loop:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
- import_tasks: consul_session.yml
|
||||
always:
|
||||
- name: Kill consul process
|
||||
shell: kill $(cat {{ output_dir }}/consul.pid)
|
||||
ignore_errors: true
|
|
@ -0,0 +1,13 @@
|
|||
# {{ ansible_managed }}
|
||||
server = true
|
||||
pid_file = "{{ remote_dir }}/consul.pid"
|
||||
ports {
|
||||
http = 8500
|
||||
{% if pyopenssl_version.stdout is version('0.15', '>=') %}
|
||||
https = 8501
|
||||
{% endif %}
|
||||
}
|
||||
{% if pyopenssl_version.stdout is version('0.15', '>=') %}
|
||||
key_file = "{{ remote_dir }}/privatekey.pem"
|
||||
cert_file = "{{ remote_dir }}/cert.pem"
|
||||
{% endif %}
|
Loading…
Add table
Add a link
Reference in a new issue