Files
community.general/tests/integration/targets/setup_etcd3/tasks/main.yml
Alexei Znamensky d06c83eb68 etcd3: re-enable and fix tests, add unit tests (#11678)
* etcd3: re-enable and fix tests, add unit tests

- Add unit tests for community.general.etcd3 module (12 tests covering
  state=present/absent, idempotency, check mode, and error paths)
- Fix integration test setup: update etcd binary to v3.6.9 (from v3.2.14),
  download from GitHub releases, add health-check retry loop after start
- Work around etcd3 Python library incompatibility with protobuf >= 4.x
  by setting PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
- Update to FQCNs throughout integration tests
- Re-enable both etcd3 and lookup_etcd3 integration targets

Fixes https://github.com/ansible-collections/community.general/issues/322

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* improve use of multiple context managers

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-25 15:55:16 +13:00

54 lines
1.8 KiB
YAML

---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# setup etcd3 for integration tests on module/lookup
# Copyright (c) 2017, Jean-Philippe Evrard <jean-philippe@evrard.me>
# Copyright (c) 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
- name: Install etcd3 Python library
ansible.builtin.pip:
name: "{{ etcd3_pip_module }}"
state: present
- name: Check if etcdctl is already usable
ansible.builtin.command: "{{ etcd3_path }}/etcdctl --endpoints=localhost:2379 endpoint health"
changed_when: false
failed_when: false
register: etcd3_health_check
- name: Set up etcd3 binary
when: etcd3_health_check.rc != 0
block:
- name: Ensure clean download directory
ansible.builtin.file:
path: "{{ etcd3_download_location }}"
state: absent
- name: Create download directory
ansible.builtin.file:
path: "{{ etcd3_download_location }}"
state: directory
- name: Download etcd3
ansible.builtin.unarchive:
src: "{{ etcd3_download_url }}"
dest: "{{ etcd3_download_location }}"
remote_src: true
- name: Start etcd3
ansible.builtin.shell: "nohup {{ etcd3_path }}/etcd > /tmp/etcd3.log 2>&1 &"
changed_when: true
- name: Wait for etcd3 to be ready
ansible.builtin.command: "{{ etcd3_path }}/etcdctl --endpoints=localhost:2379 endpoint health"
register: etcd3_ready
until: etcd3_ready.rc == 0
retries: 10
delay: 3
changed_when: false