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

[PR #4996/d214f49b backport][stable-5] consul: add support for session TTL #5038

Conversation

patchback[bot]
Copy link

@patchback patchback bot commented Jul 31, 2022

This is a backport of PR #4996 as merged into main (d214f49).

SUMMARY

This pull request add the possibility to set a TTL when creating a session.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

consul_session

ADDITIONAL INFORMATION

Without the PR it is not possible to set a TTL on a session.
Here is a test playbook

- name: test module
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Register basic session with consul
      community.general.consul_session:
        name: session-with-ttl
        # ttl: 180  # sec
    - name: Retrieve active sessions
      community.general.consul_session:
        state: list

The output of the run is the following where we can see the TTL key is an empty string where we cannot pass anything.

❯ ansible-playbook test.yaml

PLAY [test module] *************************************************************************************************************************************************************************************************************************************************************

TASK [Register basic session with consul] **************************************************************************************************************************************************************************************************************************************
changed: [localhost] => {
    "behavior": "release",
    "changed": true,
    "checks": null,
    "delay": 15,
    "invocation": { <-- we cannot invoke the module with ttl key
        "module_args": {
            "behavior": "release",
            "checks": null,
            "datacenter": null,
            "delay": 15,
            "host": "localhost",
            "id": null,
            "name": "session-with-ttl",
            "node": null,
            "port": 8500,
            "scheme": "http",
            "state": "present",
            "validate_certs": true
        }
    },
    "name": "session-with-ttl",
    "node": null,
    "session_id": "2a0919ce-3026-2a34-db91-ffa20e907aa7"
}

TASK [Retrieve active sessions] ************************************************************************************************************************************************************************************************************************************************
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "behavior": "release",
            "checks": null,
            "datacenter": null,
            "delay": 15,
            "host": "localhost",
            "id": null,
            "name": null,
            "node": null,
            "port": 8500,
            "scheme": "http",
            "state": "list",
            "validate_certs": true
        }
    },
    "sessions": [
        {
            "Behavior": "release",
            "CreateIndex": 29,
            "ID": "2a0919ce-3026-2a34-db91-ffa20e907aa7",
            "LockDelay": 15000000000,
            "ModifyIndex": 29,
            "Name": "session-with-ttl",
            "Node": "server-1",
            "NodeChecks": [
                "serfHealth"
            ],
            "ServiceChecks": null,
            "TTL": ""
        },
        {
            "Behavior": "release",
            "CreateIndex": 9,
            "ID": "93d59352-8a33-1743-7f16-b7353a615ca7",
            "LockDelay": 15000000000,
            "ModifyIndex": 9,
            "Name": "session-with-ttl",
            "Node": "server-1",
            "NodeChecks": [
                "serfHealth"
            ],
            "ServiceChecks": null,
            "TTL": ""
        },
        {
            "Behavior": "release",
            "CreateIndex": 22,
            "ID": "ea87c387-edb6-2eb6-10fd-d01eca97fe17",
            "LockDelay": 15000000000,
            "ModifyIndex": 22,
            "Name": "session-with-ttl",
            "Node": "server-1",
            "NodeChecks": [
                "serfHealth"
            ],
            "ServiceChecks": null,
            "TTL": "" <-- TTL is empty as expected
        }
    ]
}
PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

With the ttl key in the playbook above uncommented we have the following behavior where we can see the TTL key is not an empty string and have the value 180s.

❯ ansible-playbook test.yaml

PLAY [test module] *************************************************************************************************************************************************************************************************************************************************************

TASK [Register basic session with consul] **************************************************************************************************************************************************************************************************************************************
changed: [localhost] => {
    "behavior": "release",
    "changed": true,
    "checks": null,
    "delay": 15,
    "invocation": {
        "module_args": {
            "behavior": "release",
            "checks": null,
            "datacenter": null,
            "delay": 15,
            "host": "localhost",
            "id": null,
            "name": "session-with-ttl",
            "node": null,
            "port": 8500,
            "scheme": "http",
            "state": "present",
            "ttl": 180, <-- we can invoke the module with ttl
            "validate_certs": true
        }
    },
    "name": "session-with-ttl",
    "node": null,
    "session_id": "f9cf72ce-a1f4-a38b-0385-3ce8515d3a0a",
    "ttl": 180
}

TASK [Retrieve active sessions] ************************************************************************************************************************************************************************************************************************************************
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "behavior": "release",
            "checks": null,
            "datacenter": null,
            "delay": 15,
            "host": "localhost",
            "id": null,
            "name": null,
            "node": null,
            "port": 8500,
            "scheme": "http",
            "state": "list",
            "ttl": null,
            "validate_certs": true
        }
    },
    "sessions": [
        {
            "Behavior": "release",
            "CreateIndex": 9,
            "ID": "93d59352-8a33-1743-7f16-b7353a615ca7",
            "LockDelay": 15000000000,
            "ModifyIndex": 9,
            "Name": "session-with-ttl",
            "Node": "server-1",
            "NodeChecks": [
                "serfHealth"
            ],
            "ServiceChecks": null,
            "TTL": ""
        },
        {
            "Behavior": "release",
            "CreateIndex": 14,
            "ID": "f9cf72ce-a1f4-a38b-0385-3ce8515d3a0a",
            "LockDelay": 15000000000,
            "ModifyIndex": 14,
            "Name": "session-with-ttl",
            "Node": "server-1",
            "NodeChecks": [
                "serfHealth"
            ],
            "ServiceChecks": null,
            "TTL": "180s" <-- the ttl is correctly applied and visible via consul api
        }
    ]
}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Signed-off-by: Wilfried Roset <[email protected]>
(cherry picked from commit d214f49)
@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added backport clustering feature This issue/PR relates to a feature request integration tests/integration module module needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) tests tests and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 31, 2022
@felixfontein felixfontein merged commit 981c784 into stable-5 Jul 31, 2022
@felixfontein felixfontein deleted the patchback/backports/stable-5/d214f49be729b6fecea0b74f5fb0ba9b265802cb/pr-4996 branch July 31, 2022 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clustering feature This issue/PR relates to a feature request integration tests/integration module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants