1
0
Fork 0
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:
wilfriedroset 2022-07-31 13:17:43 +02:00 committed by GitHub
parent aba089369e
commit d214f49be7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- consul - adds ``ttl`` parameter for session (https://github.com/ansible-collections/community.general/pull/4996).

View file

@ -95,6 +95,11 @@ options:
choices: [ delete, release ]
type: str
default: release
ttl:
description:
- Specifies the duration of a session in seconds (between 10 and 86400).
type: int
version_added: 5.4.0
'''
EXAMPLES = '''
@ -121,6 +126,11 @@ EXAMPLES = '''
- name: Retrieve active sessions
community.general.consul_session:
state: list
- name: Register session with a ttl
community.general.consul_session:
name: session-with-ttl
ttl: 600 # sec
'''
try:
@ -185,6 +195,7 @@ def update_session(module):
datacenter = module.params.get('datacenter')
node = module.params.get('node')
behavior = module.params.get('behavior')
ttl = module.params.get('ttl')
consul_client = get_consul_api(module)
@ -192,6 +203,7 @@ def update_session(module):
session = consul_client.session.create(
name=name,
behavior=behavior,
ttl=ttl,
node=node,
lock_delay=delay,
dc=datacenter,
@ -201,6 +213,7 @@ def update_session(module):
session_id=session,
name=name,
behavior=behavior,
ttl=ttl,
delay=delay,
checks=checks,
node=node)
@ -241,6 +254,7 @@ def main():
checks=dict(type='list', elements='str'),
delay=dict(type='int', default='15'),
behavior=dict(type='str', default='release', choices=['release', 'delete']),
ttl=dict(type='int'),
host=dict(type='str', default='localhost'),
port=dict(type='int', default=8500),
scheme=dict(type='str', default='http'),

View file

@ -158,3 +158,15 @@
that:
- search_deleted is skipped # each iteration is skipped
- 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