mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
consul: add support for session TTL (#4996)
Signed-off-by: Wilfried Roset <wilfriedroset@users.noreply.github.com>
This commit is contained in:
parent
aba089369e
commit
d214f49be7
3 changed files with 28 additions and 0 deletions
2
changelogs/fragments/4996-consul-session-ttl.yml
Normal file
2
changelogs/fragments/4996-consul-session-ttl.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- consul - adds ``ttl`` parameter for session (https://github.com/ansible-collections/community.general/pull/4996).
|
|
@ -95,6 +95,11 @@ options:
|
||||||
choices: [ delete, release ]
|
choices: [ delete, release ]
|
||||||
type: str
|
type: str
|
||||||
default: release
|
default: release
|
||||||
|
ttl:
|
||||||
|
description:
|
||||||
|
- Specifies the duration of a session in seconds (between 10 and 86400).
|
||||||
|
type: int
|
||||||
|
version_added: 5.4.0
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -121,6 +126,11 @@ EXAMPLES = '''
|
||||||
- name: Retrieve active sessions
|
- name: Retrieve active sessions
|
||||||
community.general.consul_session:
|
community.general.consul_session:
|
||||||
state: list
|
state: list
|
||||||
|
|
||||||
|
- name: Register session with a ttl
|
||||||
|
community.general.consul_session:
|
||||||
|
name: session-with-ttl
|
||||||
|
ttl: 600 # sec
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -185,6 +195,7 @@ def update_session(module):
|
||||||
datacenter = module.params.get('datacenter')
|
datacenter = module.params.get('datacenter')
|
||||||
node = module.params.get('node')
|
node = module.params.get('node')
|
||||||
behavior = module.params.get('behavior')
|
behavior = module.params.get('behavior')
|
||||||
|
ttl = module.params.get('ttl')
|
||||||
|
|
||||||
consul_client = get_consul_api(module)
|
consul_client = get_consul_api(module)
|
||||||
|
|
||||||
|
@ -192,6 +203,7 @@ def update_session(module):
|
||||||
session = consul_client.session.create(
|
session = consul_client.session.create(
|
||||||
name=name,
|
name=name,
|
||||||
behavior=behavior,
|
behavior=behavior,
|
||||||
|
ttl=ttl,
|
||||||
node=node,
|
node=node,
|
||||||
lock_delay=delay,
|
lock_delay=delay,
|
||||||
dc=datacenter,
|
dc=datacenter,
|
||||||
|
@ -201,6 +213,7 @@ def update_session(module):
|
||||||
session_id=session,
|
session_id=session,
|
||||||
name=name,
|
name=name,
|
||||||
behavior=behavior,
|
behavior=behavior,
|
||||||
|
ttl=ttl,
|
||||||
delay=delay,
|
delay=delay,
|
||||||
checks=checks,
|
checks=checks,
|
||||||
node=node)
|
node=node)
|
||||||
|
@ -241,6 +254,7 @@ def main():
|
||||||
checks=dict(type='list', elements='str'),
|
checks=dict(type='list', elements='str'),
|
||||||
delay=dict(type='int', default='15'),
|
delay=dict(type='int', default='15'),
|
||||||
behavior=dict(type='str', default='release', choices=['release', 'delete']),
|
behavior=dict(type='str', default='release', choices=['release', 'delete']),
|
||||||
|
ttl=dict(type='int'),
|
||||||
host=dict(type='str', default='localhost'),
|
host=dict(type='str', default='localhost'),
|
||||||
port=dict(type='int', default=8500),
|
port=dict(type='int', default=8500),
|
||||||
scheme=dict(type='str', default='http'),
|
scheme=dict(type='str', default='http'),
|
||||||
|
|
|
@ -158,3 +158,15 @@
|
||||||
that:
|
that:
|
||||||
- search_deleted is skipped # each iteration is skipped
|
- search_deleted is skipped # each iteration is skipped
|
||||||
- search_deleted is not changed # and then unchanged
|
- search_deleted is not changed # and then unchanged
|
||||||
|
|
||||||
|
- name: ensure session can be created with a ttl
|
||||||
|
consul_session:
|
||||||
|
state: present
|
||||||
|
name: session-with-ttl
|
||||||
|
ttl: 180 # sec
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- result is changed
|
||||||
|
- result['ttl'] == 180
|
||||||
|
|
Loading…
Reference in a new issue