From 34b6509150af2746c98fbd3bb1e2e377febb5932 Mon Sep 17 00:00:00 2001 From: Philipp Waller <1090452+philippwaller@users.noreply.github.com> Date: Sun, 19 Dec 2021 19:42:52 +0100 Subject: [PATCH 1/3] Add option to assign existing users to the privileged docker user group. Signed-off-by: Philipp Waller <1090452+philippwaller@users.noreply.github.com> --- README.md | 13 +++++++++++++ defaults/main.yml | 8 ++++++++ molecule/default/converge.yml | 3 +++ molecule/default/prepare.yml | 4 ++++ molecule/default/verify.yml | 10 ++++++++++ tasks/main.yml | 16 ++++++++++++++++ 6 files changed, 54 insertions(+) create mode 100644 defaults/main.yml diff --git a/README.md b/README.md index 7084a6f..f80c31b 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,19 @@ The machine needs to be prepared. In CI this is done using `molecule/default/pre Also see a [full explanation and example](https://robertdebock.nl/how-to-use-these-roles.html) on how to use these roles. +## [Role Variables](#role-variables) + +The default values for the variables are set in `defaults/main.yml`: +```yaml +--- +# defaults file for docker_ce + +# Add users to the privileged docker group. For example: +# docker_ce_privileged_users: +# - UserA +# - UserB +docker_ce_privileged_users: +``` ## [Requirements](#requirements) diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..2b9392f --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,8 @@ +--- +# defaults file for docker_ce + +# Add users to the privileged docker group. For example: +# docker_ce_privileged_users: +# - UserA +# - UserB +docker_ce_privileged_users: diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index c56f81e..f718a7a 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -6,3 +6,6 @@ roles: - role: ansible-role-docker_ce + docker_ce_privileged_users: + - woody + - buzz diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 091e17b..9d6dea1 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -10,3 +10,7 @@ - role: robertdebock.buildtools - role: robertdebock.python_pip - role: robertdebock.core_dependencies + - role: robertdebock.users + users_user_list: + - name: woody + - name: buzz diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 780c23d..69e14f4 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -5,6 +5,16 @@ gather_facts: no tasks: + - name: Check docker group configuration + lineinfile: + path: /etc/group + regex: '^docker:x:\d*:woody,buzz$' + state: absent + check_mode: yes + register: docker_ce_group + changed_when: not docker_ce_group is changed + failed_when: docker_ce_group is changed + - name: install pip docker-py ansible.builtin.pip: name: docker-py diff --git a/tasks/main.yml b/tasks/main.yml index 80d8a24..24cd452 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -36,6 +36,22 @@ name: "{{ docker_ce_packages }}" state: present +- name: create privileged docker user group + ansible.builtin.group: + name: docker + state: present + +- name: adding existing user '{{ user }}' to group docker + user: + name: '{{ user }}' + groups: docker + append: yes + loop: "{{ docker_ce_privileged_users }}" + loop_control: + loop_var: user + when: + - docker_ce_privileged_users | length + - name: start and enable docker_ce ansible.builtin.service: name: "{{ docker_ce_service }}" From f59470e316f701f06f65a609b496faf8f6aabe35 Mon Sep 17 00:00:00 2001 From: Philipp Waller <1090452+philippwaller@users.noreply.github.com> Date: Mon, 20 Dec 2021 10:12:47 +0100 Subject: [PATCH 2/3] Change test user creation strategy to avoid unit test specific dependencies. Signed-off-by: Philipp Waller <1090452+philippwaller@users.noreply.github.com> --- molecule/default/prepare.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 9d6dea1..cedbf83 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -10,7 +10,13 @@ - role: robertdebock.buildtools - role: robertdebock.python_pip - role: robertdebock.core_dependencies - - role: robertdebock.users - users_user_list: - - name: woody - - name: buzz + + tasks: + - name: Create test case users + user: + name: "{{ user }}" + loop: + - woody + - buzz + loop_control: + loop_var: user From 1956eb43c5eeb4491de17d3bff382b3bb40096aa Mon Sep 17 00:00:00 2001 From: Philipp Waller <1090452+philippwaller@users.noreply.github.com> Date: Mon, 20 Dec 2021 10:28:30 +0100 Subject: [PATCH 3/3] Improve task description. Signed-off-by: Philipp Waller <1090452+philippwaller@users.noreply.github.com> --- tasks/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 24cd452..41fc5a9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -41,9 +41,9 @@ name: docker state: present -- name: adding existing user '{{ user }}' to group docker +- name: add privileged users to the docker user group user: - name: '{{ user }}' + name: "{{ user }}" groups: docker append: yes loop: "{{ docker_ce_privileged_users }}"