1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/setup_etcd3/tasks/main.yml

105 lines
3.2 KiB
YAML
Raw Normal View History

add etcd3 lookup plugin (#127) * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * changes: - replace kwargs lookups with get_option() - add 'entpoint' option for correct handling of ETCDCTL_ENDPOINTS env - code simplification * fix etcd3 lookup unit test: replace LookupModule instanciation with lookup_loader * fix sanity checks * etcd3 changes: - docstring documentation fixes/updates - create etcd3 cnx object with a get_option() loop instead of copying 'private' class object - set 'endpoints' option mutually exclusive with 'host' and 'port' (raises an AnsibleError exception) * etcd3 changes: - added ANSIBLE_METADATA, - added default value for 'endpoints' option, - removed defaults for options 'host' and 'port', - fixed docstring links, - added 'notes' and 'seealso' sections in doctring - updated options code handling to reflect docstring's updates * etcd3 changes: - fix descriptions for endpoints, host, and port options - update notes sections - fix reference to etcd lookup plugin in seealso section - fix return docstring - remove useless logging - obfuscates password in connection logging * more pythonic lookup on dict keys Co-Authored-By: Felix Fontein <felix@fontein.de> * Update password obfuscation Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2020-04-25 10:58:06 +02:00
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
add etcd3 lookup plugin (#127) * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * changes: - replace kwargs lookups with get_option() - add 'entpoint' option for correct handling of ETCDCTL_ENDPOINTS env - code simplification * fix etcd3 lookup unit test: replace LookupModule instanciation with lookup_loader * fix sanity checks * etcd3 changes: - docstring documentation fixes/updates - create etcd3 cnx object with a get_option() loop instead of copying 'private' class object - set 'endpoints' option mutually exclusive with 'host' and 'port' (raises an AnsibleError exception) * etcd3 changes: - added ANSIBLE_METADATA, - added default value for 'endpoints' option, - removed defaults for options 'host' and 'port', - fixed docstring links, - added 'notes' and 'seealso' sections in doctring - updated options code handling to reflect docstring's updates * etcd3 changes: - fix descriptions for endpoints, host, and port options - update notes sections - fix reference to etcd lookup plugin in seealso section - fix return docstring - remove useless logging - obfuscates password in connection logging * more pythonic lookup on dict keys Co-Authored-By: Felix Fontein <felix@fontein.de> * Update password obfuscation Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2020-04-25 10:58:06 +02:00
# setup etcd3 for integration tests on module/lookup
# Copyright 2017, Jean-Philippe Evrard <jean-philippe@evrard.me>
# Copyright 2020, SCC France, Eric Belhomme <ebelhomme@fr.scc.com>
# 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
add etcd3 lookup plugin (#127) * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * changes: - replace kwargs lookups with get_option() - add 'entpoint' option for correct handling of ETCDCTL_ENDPOINTS env - code simplification * fix etcd3 lookup unit test: replace LookupModule instanciation with lookup_loader * fix sanity checks * etcd3 changes: - docstring documentation fixes/updates - create etcd3 cnx object with a get_option() loop instead of copying 'private' class object - set 'endpoints' option mutually exclusive with 'host' and 'port' (raises an AnsibleError exception) * etcd3 changes: - added ANSIBLE_METADATA, - added default value for 'endpoints' option, - removed defaults for options 'host' and 'port', - fixed docstring links, - added 'notes' and 'seealso' sections in doctring - updated options code handling to reflect docstring's updates * etcd3 changes: - fix descriptions for endpoints, host, and port options - update notes sections - fix reference to etcd lookup plugin in seealso section - fix return docstring - remove useless logging - obfuscates password in connection logging * more pythonic lookup on dict keys Co-Authored-By: Felix Fontein <felix@fontein.de> * Update password obfuscation Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2020-04-25 10:58:06 +02:00
# ============================================================
# setup etcd3 for supported distros
- block:
- name: python 2
set_fact:
python_suffix: ""
when: ansible_python_version is version('3', '<')
- name: python 3
set_fact:
python_suffix: "-py3"
when: ansible_python_version is version('3', '>=')
- include_vars: '{{ item }}'
with_first_found:
- files:
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}{{ python_suffix }}.yml'
- '{{ ansible_distribution }}-{{ ansible_distribution_version }}{{ python_suffix }}.yml'
- '{{ ansible_os_family }}-{{ ansible_distribution_major_version }}{{ python_suffix }}.yml'
- '{{ ansible_os_family }}{{ python_suffix }}.yml'
- 'default{{ python_suffix }}.yml'
- 'default.yml'
paths: '../vars'
- name: Upgrade setuptools python2 module
pip:
name: setuptools<45
extra_args: --upgrade
state: present
when: python_suffix == ''
- name: Install etcd3 python modules
pip:
name: "{{ etcd3_pip_module }}"
extra_args: --only-binary grpcio
state: present
# Check if re-installing etcd3 is required
- name: Check if etcd3ctl exists for reuse.
add etcd3 lookup plugin (#127) * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * changes: - replace kwargs lookups with get_option() - add 'entpoint' option for correct handling of ETCDCTL_ENDPOINTS env - code simplification * fix etcd3 lookup unit test: replace LookupModule instanciation with lookup_loader * fix sanity checks * etcd3 changes: - docstring documentation fixes/updates - create etcd3 cnx object with a get_option() loop instead of copying 'private' class object - set 'endpoints' option mutually exclusive with 'host' and 'port' (raises an AnsibleError exception) * etcd3 changes: - added ANSIBLE_METADATA, - added default value for 'endpoints' option, - removed defaults for options 'host' and 'port', - fixed docstring links, - added 'notes' and 'seealso' sections in doctring - updated options code handling to reflect docstring's updates * etcd3 changes: - fix descriptions for endpoints, host, and port options - update notes sections - fix reference to etcd lookup plugin in seealso section - fix return docstring - remove useless logging - obfuscates password in connection logging * more pythonic lookup on dict keys Co-Authored-By: Felix Fontein <felix@fontein.de> * Update password obfuscation Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2020-04-25 10:58:06 +02:00
shell: "ETCDCTL_API=3 {{ etcd3_path }}/etcdctl --endpoints=localhost:2379 get foo"
args:
executable: /bin/bash
changed_when: false
failed_when: false
register: _testetcd3ctl
- block:
# Installing etcd3
- name: If can't reuse, prepare download folder
file:
path: "{{ etcd3_download_location }}"
state: directory
register: _etcddownloadexists
when:
- _testetcd3ctl.rc != 0
- name: Delete download folder if already exists (to start clean)
file:
path: "{{ etcd3_download_location }}"
state: absent
when:
- _etcddownloadexists is not changed
- name: Recreate download folder if purged
file:
path: "{{ etcd3_download_location }}"
state: directory
when:
- _etcddownloadexists is not changed
- name: Download etcd3
unarchive:
src: "{{ etcd3_download_url }}"
dest: "{{ etcd3_download_location }}"
remote_src: true
add etcd3 lookup plugin (#127) * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * add etcd3 lookup plugin * retire version_added tag Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * fix YAML syntax in example Co-Authored-By: Felix Fontein <felix@fontein.de> * typo fixes Co-Authored-By: Felix Fontein <felix@fontein.de> * remove python shebang as it is useless in Ansible lookup module Co-Authored-By: Felix Fontein <felix@fontein.de> * Update plugins/lookup/etcd3.py typo Co-Authored-By: Felix Fontein <felix@fontein.de> * fixes: - replaced LookupBase._display by ansible.utils.display.Display - add regex to retrieve host and port from ETCDCTL_ENDPOINTS env - add env support for user, password, timeout * fixes: - use short form for types - update doc section with envs - catch exceptions between etcd3 api calls * etcd3 lookup pass ansible sanity checks introduce ansible integration tests for etcd3 lookup * extract etcd3 setup from existing etcd3 module integration test * fix etcd3 module/lookup integration tests * fixes: - fix port option in docstring - raise connecttion error - fix display format issues - fix ETCDCTL_ENDPOINTS regex adds: - basic unit tests * fix sanity issues * changes: - replace kwargs lookups with get_option() - add 'entpoint' option for correct handling of ETCDCTL_ENDPOINTS env - code simplification * fix etcd3 lookup unit test: replace LookupModule instanciation with lookup_loader * fix sanity checks * etcd3 changes: - docstring documentation fixes/updates - create etcd3 cnx object with a get_option() loop instead of copying 'private' class object - set 'endpoints' option mutually exclusive with 'host' and 'port' (raises an AnsibleError exception) * etcd3 changes: - added ANSIBLE_METADATA, - added default value for 'endpoints' option, - removed defaults for options 'host' and 'port', - fixed docstring links, - added 'notes' and 'seealso' sections in doctring - updated options code handling to reflect docstring's updates * etcd3 changes: - fix descriptions for endpoints, host, and port options - update notes sections - fix reference to etcd lookup plugin in seealso section - fix return docstring - remove useless logging - obfuscates password in connection logging * more pythonic lookup on dict keys Co-Authored-By: Felix Fontein <felix@fontein.de> * Update password obfuscation Co-Authored-By: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
2020-04-25 10:58:06 +02:00
# Running etcd3 and kill afterwards if it wasn't running before.
- name: Run etcd3
shell: "{{ etcd3_path }}/etcd &"
register: _etcd3run
changed_when: true
# - name: kill etcd3
# command: "pkill etcd"
when:
- _testetcd3ctl.rc != 0
when:
- ansible_distribution | lower ~ "-" ~ ansible_distribution_major_version | lower != 'centos-6'