diff --git a/changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml b/changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml new file mode 100644 index 00000000000..269efb86e48 --- /dev/null +++ b/changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_swarm_service - fix task always reporting as changed when using ``healthcheck.start_period``." diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index e4d2f3f100d..359f84972e6 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -2270,10 +2270,16 @@ class DockerServiceManager(object): healthcheck_data = task_template_data['ContainerSpec'].get('Healthcheck') if healthcheck_data: - options = ['test', 'interval', 'timeout', 'start_period', 'retries'] + options = { + 'Test': 'test', + 'Interval': 'interval', + 'Timeout': 'timeout', + 'StartPeriod': 'start_period', + 'Retries': 'retries' + } healthcheck = dict( - (key.lower(), value) for key, value in healthcheck_data.items() - if value is not None and key.lower() in options + (options[key], value) for key, value in healthcheck_data.items() + if value is not None and key in options ) ds.healthcheck = healthcheck @@ -2882,8 +2888,8 @@ def main(): usage_msg='set publish.mode' ), healthcheck_start_period=dict( - docker_py_version='2.4.0', - docker_api_version='1.25', + docker_py_version='2.6.0', + docker_api_version='1.29', detect_usage=_detect_healthcheck_start_period, usage_msg='set healthcheck.start_period' ), diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml index 035dc08d8e7..1f805bacc3e 100644 --- a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml +++ b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml @@ -909,6 +909,7 @@ timeout: 2s interval: 0h0m2s3ms4us retries: 2 + start_period: 20s register: healthcheck_1 ignore_errors: yes @@ -926,6 +927,7 @@ timeout: 2s interval: 0h0m2s3ms4us retries: 2 + start_period: 20s register: healthcheck_2 ignore_errors: yes @@ -1029,12 +1031,12 @@ - healthcheck_7 is not changed - healthcheck_8 is changed - healthcheck_9 is not changed - when: docker_api_version is version('1.25', '>=') and docker_py_version is version('2.6.0', '>=') + when: docker_api_version is version('1.29', '>=') and docker_py_version is version('2.6.0', '>=') - assert: that: - healthcheck_1 is failed - "'Minimum version required' in healthcheck_1.msg" - when: docker_api_version is version('1.25', '<') or docker_py_version is version('2.6.0', '<') + when: docker_api_version is version('1.29', '<') or docker_py_version is version('2.6.0', '<') ################################################################### ## hostname #######################################################