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 ] 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'),

View file

@ -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