From c7a3d9f057f853c99028430f123a26effe433b03 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 3 Jan 2021 13:30:09 +0100 Subject: [PATCH] docker_container: cgroup_parent (#59) * Document that the Docker SDK for Python is used by the module. * Allow to specify cgroup_parent for container. --- .../59-docker_container-cgroup-parent.yml | 2 ++ plugins/doc_fragments/docker.py | 6 ++++ plugins/modules/docker_container.py | 8 +++++ .../docker_container/tasks/tests/options.yml | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 changelogs/fragments/59-docker_container-cgroup-parent.yml diff --git a/changelogs/fragments/59-docker_container-cgroup-parent.yml b/changelogs/fragments/59-docker_container-cgroup-parent.yml new file mode 100644 index 000000000..a1e5e70cb --- /dev/null +++ b/changelogs/fragments/59-docker_container-cgroup-parent.yml @@ -0,0 +1,2 @@ +minor_changes: +- "docker_container - support specifying ``cgroup_parent`` (https://github.com/ansible-collections/community.docker/issues/6, https://github.com/ansible-collections/community.docker/pull/59)." diff --git a/plugins/doc_fragments/docker.py b/plugins/doc_fragments/docker.py index ad3efb1f7..f0d06e64e 100644 --- a/plugins/doc_fragments/docker.py +++ b/plugins/doc_fragments/docker.py @@ -111,6 +111,9 @@ class ModuleDocFragment(object): DOCKER_PY_1_DOCUMENTATION = r''' options: {} +notes: + - This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to + communicate with the Docker daemon. requirements: - "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/) Python module has been superseded by L(docker,https://pypi.org/project/docker/) @@ -127,6 +130,9 @@ class ModuleDocFragment(object): DOCKER_PY_2_DOCUMENTATION = r''' options: {} +notes: + - This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to + communicate with the Docker daemon. requirements: - "Python >= 2.7" - "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/) diff --git a/plugins/modules/docker_container.py b/plugins/modules/docker_container.py index 3c41f2111..4f79ad568 100644 --- a/plugins/modules/docker_container.py +++ b/plugins/modules/docker_container.py @@ -52,6 +52,11 @@ - List of capabilities to drop from the container. type: list elements: str + cgroup_parent: + description: + - Specify the parent cgroup for the container. + type: str + version_added: 1.1.0 cleanup: description: - Use with I(detach=false) to remove the container after successful execution. @@ -1596,6 +1601,7 @@ def _host_config(self): publish_all_ports='publish_all_ports', links='links', privileged='privileged', + cgroup_parent='cgroup_parent', dns='dns_servers', dns_opt='dns_opts', dns_search='dns_search_domains', @@ -2190,6 +2196,7 @@ def has_different_configuration(self, image): interactive=config.get('OpenStdin'), capabilities=host_config.get('CapAdd'), cap_drop=host_config.get('CapDrop'), + cgroup_parent=host_config.get('CgroupParent'), expected_devices=host_config.get('Devices'), dns_servers=host_config.get('Dns'), dns_opts=host_config.get('DnsOptions'), @@ -3389,6 +3396,7 @@ def main(): blkio_weight=dict(type='int'), capabilities=dict(type='list', elements='str'), cap_drop=dict(type='list', elements='str'), + cgroup_parent=dict(type='str'), cleanup=dict(type='bool', default=False), command=dict(type='raw'), comparisons=dict(type='dict'), diff --git a/tests/integration/targets/docker_container/tasks/tests/options.yml b/tests/integration/targets/docker_container/tasks/tests/options.yml index 007952afb..582b737e2 100644 --- a/tests/integration/targets/docker_container/tasks/tests/options.yml +++ b/tests/integration/targets/docker_container/tasks/tests/options.yml @@ -157,6 +157,40 @@ - capabilities_3 is not changed - capabilities_4 is changed +#################################################################### +## cgroup_parent ################################################### +#################################################################### + +- name: cgroup_parent + docker_container: + image: "{{ docker_test_image_alpine }}" + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + cgroup_parent: '' + register: cgroup_parent_1 + +- name: cgroup_parent (idempotency) + docker_container: + image: "{{ docker_test_image_alpine }}" + command: '/bin/sh -c "sleep 10m"' + name: "{{ cname }}" + state: started + cgroup_parent: '' + register: cgroup_parent_2 + +- name: cleanup + docker_container: + name: "{{ cname }}" + state: absent + force_kill: yes + diff: no + +- assert: + that: + - cgroup_parent_1 is changed + - cgroup_parent_2 is not changed + #################################################################### ## command ######################################################### ####################################################################