mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
157 lines
3.5 KiB
YAML
157 lines
3.5 KiB
YAML
|
- name: cleanup any previous failed runs
|
||
|
consul:
|
||
|
service_id: '{{item}}'
|
||
|
state: absent
|
||
|
with_items:
|
||
|
- service1
|
||
|
- service2
|
||
|
- with_check
|
||
|
- with_tags
|
||
|
|
||
|
- name: register very basic service with consul gets default id
|
||
|
consul:
|
||
|
service_name: service1
|
||
|
service_port: 80
|
||
|
register: basic_result
|
||
|
|
||
|
- name: verify basic service registration
|
||
|
assert:
|
||
|
that:
|
||
|
- basic_result.changed
|
||
|
- basic_result.service_port == 80
|
||
|
- basic_result.service_id == 'service1'
|
||
|
- basic_result.service_name == 'service1'
|
||
|
|
||
|
- name: register very basic service with explicit id
|
||
|
consul:
|
||
|
service_name: Basic Service
|
||
|
service_id: service2
|
||
|
service_port: 80
|
||
|
register: basic2_result
|
||
|
|
||
|
- name: verify service2 registration
|
||
|
assert:
|
||
|
that:
|
||
|
- basic2_result.changed
|
||
|
- basic2_result.service_port == 80
|
||
|
- basic2_result.service_id == 'service2'
|
||
|
- basic2_result.service_name == 'Basic Service'
|
||
|
|
||
|
- name: register very basic service with check script
|
||
|
consul:
|
||
|
service_name: with_check
|
||
|
service_port: 80
|
||
|
script: "sh -c true"
|
||
|
interval: 60
|
||
|
register: script_result
|
||
|
|
||
|
- name: verify service with check registration
|
||
|
assert:
|
||
|
that:
|
||
|
- script_result.changed
|
||
|
- script_result.service_port == 80
|
||
|
- script_result.service_id == 'with_check'
|
||
|
- script_result.checks | length == 1
|
||
|
|
||
|
- name: register service with some service tags
|
||
|
consul:
|
||
|
service_name: with_tags
|
||
|
service_port: 80
|
||
|
tags:
|
||
|
- prod
|
||
|
- webservers
|
||
|
register: tags_result
|
||
|
|
||
|
|
||
|
- name: verify tags registration
|
||
|
assert:
|
||
|
that:
|
||
|
- tags_result.changed
|
||
|
- "tags_result.tags == ['prod', 'webservers']"
|
||
|
|
||
|
- name: create a node level check
|
||
|
consul:
|
||
|
check_name: Node Level Check
|
||
|
check_id: node_level
|
||
|
script: "sh -c true"
|
||
|
interval: 50m
|
||
|
register: nodelevel_result
|
||
|
|
||
|
- name: verify service with check registration
|
||
|
assert:
|
||
|
that:
|
||
|
- nodelevel_result.changed
|
||
|
- nodelevel_result.check_name == 'Node Level Check'
|
||
|
- nodelevel_result.check_id == 'node_level'
|
||
|
- nodelevel_result.script == 'sh -c true'
|
||
|
- nodelevel_result.interval == '50m'
|
||
|
|
||
|
- name: remove a service
|
||
|
consul:
|
||
|
service_id: 'service1'
|
||
|
state: absent
|
||
|
register: delete_service_result
|
||
|
|
||
|
- name: verify service removal
|
||
|
assert:
|
||
|
that:
|
||
|
- delete_service_result.changed
|
||
|
|
||
|
- name: removal of an non-existant service causes no change
|
||
|
consul:
|
||
|
service_id: 'service1'
|
||
|
state: absent
|
||
|
register: delete_service_result
|
||
|
|
||
|
- name: verify service removal caused no change
|
||
|
assert:
|
||
|
that:
|
||
|
- not delete_service_result.changed
|
||
|
|
||
|
- name: remove a check
|
||
|
consul:
|
||
|
check_id: 'node_level'
|
||
|
state: absent
|
||
|
register: delete_check_result
|
||
|
|
||
|
- name: verify check removal
|
||
|
assert:
|
||
|
that:
|
||
|
- delete_check_result.changed
|
||
|
|
||
|
- name: removal of an non-existant check causes no change
|
||
|
consul:
|
||
|
check_id: 'node_level'
|
||
|
state: absent
|
||
|
register: delete_check_result
|
||
|
|
||
|
- name: verify check removal cause no change
|
||
|
assert:
|
||
|
that:
|
||
|
- not delete_service_result.changed
|
||
|
|
||
|
- name: add service to test removal by name
|
||
|
consul:
|
||
|
service_name: by_name
|
||
|
service_port: 12345
|
||
|
|
||
|
- name: remove service by name
|
||
|
consul:
|
||
|
service_name: by_name
|
||
|
state: absent
|
||
|
register: delete_service_by_name_result
|
||
|
|
||
|
- name: verify service removal
|
||
|
assert:
|
||
|
that:
|
||
|
- delete_service_by_name_result.changed
|
||
|
|
||
|
- name: cleanup
|
||
|
consul:
|
||
|
service_id: '{{item}}'
|
||
|
state: absent
|
||
|
with_items:
|
||
|
- service2
|
||
|
- with_check
|
||
|
- with_tags
|