mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-29 16:11:22 -07:00
[PR #7989/03966624 backport][stable-9] Consul implement agent service and check (#8513)
Consul implement agent service and check (#7989)
* Implement agent service and check (#7987)
* implement update of service and check
* update tests
update documentation
* update documentation
* add consul_agent_check/service to action_groups
check if unique_identifier of name is in params to get object
add suggested improvements
* update sanity
* fix sanity issues
update documentation
* fix naming
* fix naming
check if response_data has data
* fix sanity extra-docs
* add as ignore maintainer in BOTMETA.yml
update version_added to 8.4
* fix sanity
* add to maintainers
* Update plugins/modules/consul_agent_check.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/consul_agent_check.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* Update plugins/modules/consul_agent_check.py
Co-authored-by: Felix Fontein <felix@fontein.de>
* update version_added
* if create and update return no object as result we read the object again
* get_first_appearing_identifier check the params for the given identifier and return it to simplify id vs name
* add unique_identifiers as a new property and a method to decide which identifier should be used
* fix sanity
* add self to team consul
remove params with no values
add operational_attributes that inherited classes can set them
get identifier value from object
* fix sanity
fix test
* remove the possibility to add checks with consul_agent_check.
check if service has changed
* remove tests for idempotency check because for checks it is not possible
* remove unique_identifier from consul.py
change unique_identifier to unique_identifiers
* get id from params
* Revert "remove unique_identifier from consul.py"
This reverts commit a4f0d0220dd23e95871914b152c25ff352097a2c.
* update version to 8.5
* Revert "Revert "remove unique_identifier from consul.py""
This reverts commit d2c35cf04c8aaf5f0175d772f862a796e22e35d4.
* update description
update test
* fix sanity tests
* fix sanity tests
* update documentation for agent_check
* fix line length
* add documentation
* fix sanity
* simplified check for Tcp
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* check duration with regex
* fix
* update documentation
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
(cherry picked from commit 03966624ba
)
Co-authored-by: Ilgmi <michael.ilg@mailbox.org>
This commit is contained in:
parent
d6168a196b
commit
2d26fba0b9
13 changed files with 810 additions and 21 deletions
114
tests/integration/targets/consul/tasks/consul_agent_check.yml
Normal file
114
tests/integration/targets/consul/tasks/consul_agent_check.yml
Normal file
|
@ -0,0 +1,114 @@
|
|||
---
|
||||
# Copyright (c) 2024, Michael Ilg (@Ilgmi)
|
||||
# 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: Create a service
|
||||
community.general.consul_agent_service:
|
||||
name: nginx
|
||||
service_port: 80
|
||||
address: localhost
|
||||
tags:
|
||||
- http
|
||||
meta:
|
||||
nginx_version: 1.25.3
|
||||
register: result
|
||||
|
||||
- set_fact:
|
||||
nginx_service: "{{result.service}}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.service.ID is defined
|
||||
|
||||
- name: Add a check for service
|
||||
community.general.consul_agent_check:
|
||||
name: nginx_check
|
||||
id: nginx_check
|
||||
interval: 30s
|
||||
http: http://localhost:80/morestatus
|
||||
notes: "Nginx Check"
|
||||
service_id: "{{ nginx_service.ID }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.check is defined
|
||||
- result.check.CheckID == 'nginx_check'
|
||||
- result.check.ServiceID == 'nginx'
|
||||
- result.check.Interval == '30s'
|
||||
- result.check.Type == 'http'
|
||||
- result.check.Notes == 'Nginx Check'
|
||||
|
||||
- set_fact:
|
||||
nginx_service_check: "{{ result.check }}"
|
||||
|
||||
- name: Update check for service
|
||||
community.general.consul_agent_check:
|
||||
name: "{{ nginx_service_check.Name }}"
|
||||
id: "{{ nginx_service_check.CheckID }}"
|
||||
interval: 60s
|
||||
http: http://localhost:80/morestatus
|
||||
notes: "New Nginx Check"
|
||||
service_id: "{{ nginx_service.ID }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.check is defined
|
||||
- result.check.CheckID == 'nginx_check'
|
||||
- result.check.ServiceID == 'nginx'
|
||||
- result.check.Interval == '1m0s'
|
||||
- result.check.Type == 'http'
|
||||
- result.check.Notes == 'New Nginx Check'
|
||||
|
||||
- name: Remove check
|
||||
community.general.consul_agent_check:
|
||||
id: "{{ nginx_service_check.Name }}"
|
||||
state: absent
|
||||
service_id: "{{ nginx_service.ID }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is not failed
|
||||
- result.operation == 'remove'
|
||||
|
||||
- name: Add a check
|
||||
community.general.consul_agent_check:
|
||||
name: check
|
||||
id: check
|
||||
interval: 30s
|
||||
tcp: localhost:80
|
||||
notes: "check"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.check is defined
|
||||
|
||||
- name: Update a check
|
||||
community.general.consul_agent_check:
|
||||
name: check
|
||||
id: check
|
||||
interval: 60s
|
||||
tcp: localhost:80
|
||||
notes: "check"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.check is defined
|
||||
- result.check.Interval == '1m0s'
|
||||
|
||||
- name: Remove check
|
||||
community.general.consul_agent_check:
|
||||
id: check
|
||||
state: absent
|
||||
register: result
|
|
@ -0,0 +1,89 @@
|
|||
---
|
||||
# Copyright (c) 2024, Michael Ilg (@Ilgmi)
|
||||
# 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: Create a service
|
||||
community.general.consul_agent_service:
|
||||
name: nginx
|
||||
service_port: 80
|
||||
address: localhost
|
||||
tags:
|
||||
- http
|
||||
meta:
|
||||
nginx_version: 1.25.3
|
||||
register: result
|
||||
|
||||
- set_fact:
|
||||
nginx_service: "{{result.service}}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.service.ID is defined
|
||||
- result.service.Service == 'nginx'
|
||||
- result.service.Address == 'localhost'
|
||||
- result.service.Port == 80
|
||||
- result.service.Tags[0] == 'http'
|
||||
- result.service.Meta.nginx_version is defined
|
||||
- result.service.Meta.nginx_version == '1.25.3'
|
||||
- result.service.ContentHash is defined
|
||||
|
||||
- name: Update service
|
||||
community.general.consul_agent_service:
|
||||
id: "{{ nginx_service.ID }}"
|
||||
name: "{{ nginx_service.Service }}"
|
||||
service_port: 8080
|
||||
address: 127.0.0.1
|
||||
tags:
|
||||
- http
|
||||
- new_tag
|
||||
meta:
|
||||
nginx_version: 1.0.0
|
||||
nginx: 1.25.3
|
||||
register: result
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.service.ID is defined
|
||||
- result.service.Service == 'nginx'
|
||||
- result.service.Address == '127.0.0.1'
|
||||
- result.service.Port == 8080
|
||||
- result.service.Tags[0] == 'http'
|
||||
- result.service.Tags[1] == 'new_tag'
|
||||
- result.service.Meta.nginx_version is defined
|
||||
- result.service.Meta.nginx_version == '1.0.0'
|
||||
- result.service.Meta.nginx is defined
|
||||
- result.service.Meta.nginx == '1.25.3'
|
||||
- result.service.ContentHash is defined
|
||||
|
||||
- name: Update service not changed when updating again without changes
|
||||
community.general.consul_agent_service:
|
||||
id: "{{ nginx_service.ID }}"
|
||||
name: "{{ nginx_service.Service }}"
|
||||
service_port: 8080
|
||||
address: 127.0.0.1
|
||||
tags:
|
||||
- http
|
||||
- new_tag
|
||||
meta:
|
||||
nginx_version: 1.0.0
|
||||
nginx: 1.25.3
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is not changed
|
||||
- result.operation is not defined
|
||||
|
||||
- name: Remove service
|
||||
community.general.consul_agent_service:
|
||||
id: "{{ nginx_service.ID }}"
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is not failed
|
||||
- result.operation == 'remove'
|
|
@ -97,6 +97,8 @@
|
|||
- import_tasks: consul_token.yml
|
||||
- import_tasks: consul_auth_method.yml
|
||||
- import_tasks: consul_binding_rule.yml
|
||||
- import_tasks: consul_agent_service.yml
|
||||
- import_tasks: consul_agent_check.yml
|
||||
module_defaults:
|
||||
group/community.general.consul:
|
||||
token: "{{ consul_management_token }}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue