mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-11 08:34:21 -07:00
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>
This commit is contained in:
parent
61cf2b74c4
commit
695eed943b
17 changed files with 510 additions and 0 deletions
22
tests/integration/targets/lookup_etcd3/tasks/main.yml
Normal file
22
tests/integration/targets/lookup_etcd3/tasks/main.yml
Normal file
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
# lookup_etcd3 integration tests
|
||||
# 2020, SCC France, Eric Belhomme <ebelhomme@fr.scc.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- name: put key/values with an etcd prefix
|
||||
etcd3:
|
||||
key: "{{ etcd3_prefix }}foo{{ item }}"
|
||||
value: "bar{{ item }}"
|
||||
state: present
|
||||
loop:
|
||||
- 1
|
||||
- 2
|
||||
- 3
|
||||
|
||||
- name: put a single key/values in etcd
|
||||
etcd3:
|
||||
key: "{{ etcd3_singlekey }}"
|
||||
value: "foobar"
|
||||
state: present
|
||||
|
||||
- import_tasks: tests.yml
|
26
tests/integration/targets/lookup_etcd3/tasks/tests.yml
Normal file
26
tests/integration/targets/lookup_etcd3/tasks/tests.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
# lookup_etcd3 integration tests
|
||||
# 2020, SCC France, Eric Belhomme <ebelhomme@fr.scc.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- block:
|
||||
- name: 'Fetch secrets using "etcd3" lookup'
|
||||
set_fact:
|
||||
etcdoutkey1: "{{ lookup('community.general.etcd3', etcd3_prefix, prefix=True) }}"
|
||||
etcdoutkey2: "{{ lookup('community.general.etcd3', etcd3_singlekey) }}"
|
||||
key_inexistent: "{{ lookup('community.general.etcd3', 'inexistent_key') }}"
|
||||
|
||||
- name: 'Check etcd values'
|
||||
assert:
|
||||
msg: 'unexpected etcd3 values'
|
||||
that:
|
||||
- etcdoutkey1 is sequence
|
||||
- etcdoutkey1 | length() == 3
|
||||
- etcdoutkey1[0].value == 'bar1'
|
||||
- etcdoutkey1[1].value == 'bar2'
|
||||
- etcdoutkey1[2].value == 'bar3'
|
||||
- etcdoutkey2 is sequence
|
||||
- etcdoutkey2 | length() == 2
|
||||
- etcdoutkey2.value == 'foobar'
|
||||
- key_inexistent is sequence
|
||||
- key_inexistent | length() == 0
|
Loading…
Add table
Add a link
Reference in a new issue