Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consul: add support for session TTL #4996

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/4996-consul-session-ttl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- consul - adds ``ttl`` parameter for session (https://github.com/ansible-collections/community.general/pull/4996).
14 changes: 14 additions & 0 deletions plugins/modules/clustering/consul/consul_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
choices: [ delete, release ]
type: str
default: release
ttl:
description:
- Specifies the duration of a session in seconds (between 10 and 86400).
type: int
wilfriedroset marked this conversation as resolved.
Show resolved Hide resolved
version_added: 5.4.0
'''

EXAMPLES = '''
Expand All @@ -121,6 +126,11 @@
- 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:
Expand Down Expand Up @@ -185,13 +195,15 @@ 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)

try:
session = consul_client.session.create(
name=name,
behavior=behavior,
ttl=ttl,
node=node,
lock_delay=delay,
dc=datacenter,
Expand All @@ -201,6 +213,7 @@ def update_session(module):
session_id=session,
name=name,
behavior=behavior,
ttl=ttl,
delay=delay,
checks=checks,
node=node)
Expand Down Expand Up @@ -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'),
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/targets/consul/tasks/consul_session.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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