From 2bf1b29d3f9f14dbc1d19ddd9c936c11c0328f23 Mon Sep 17 00:00:00 2001 From: James McCallum Date: Sun, 3 Sep 2017 19:21:17 +1000 Subject: [PATCH 1/5] Add user to docker group functionality --- README.md | 6 ++++++ defaults/main.yml | 3 +++ tasks/docker-users.yml | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 tasks/docker-users.yml diff --git a/README.md b/README.md index efe0421..4edabe7 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,12 @@ Docker Compose installation options. (Used only for RedHat/CentOS.) You can enable the Edge or Test repo by setting the respective vars to `1`. +Set the docker_users variable to allow those users to run docker (these users are added to the docker group) + + docker_users: + - Guy + - James + ## Use with Ansible (and `docker` Python library) Many users of this role wish to also use Ansible to then _build_ Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the `docker` Python library using the `geerlingguy.pip` role: diff --git a/defaults/main.yml b/defaults/main.yml index 14e91a7..21fdbf1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -17,3 +17,6 @@ docker_apt_repository: "deb https://download.docker.com/linux/{{ ansible_distrib docker_yum_repo_url: https://download.docker.com/linux/centos/docker-{{ docker_edition }}.repo docker_yum_repo_enable_edge: 0 docker_yum_repo_enable_test: 0 + +# Docker users +docker_users: [] diff --git a/tasks/docker-users.yml b/tasks/docker-users.yml new file mode 100644 index 0000000..6b35881 --- /dev/null +++ b/tasks/docker-users.yml @@ -0,0 +1,6 @@ +--- +- name: Add users to docker group + user: + name: "{{ item }}" + group: docker + with_items: "{{ docker_users }}" From 8c63471573fc4bbbf35880b6a91ab94f4236f723 Mon Sep 17 00:00:00 2001 From: James McCallum Date: Sun, 3 Sep 2017 19:38:50 +1000 Subject: [PATCH 2/5] include docker-users to main --- tasks/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index ba197cf..7b08d54 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -16,3 +16,6 @@ - include: docker-compose.yml when: docker_install_compose + +- include: docker-users.yml + when: docker_users From e68f0cbd16beb7dcabd5b2eacccce09d151d3981 Mon Sep 17 00:00:00 2001 From: James McCallum Date: Tue, 26 Sep 2017 05:09:58 +1000 Subject: [PATCH 3/5] Fix docker group to append group rather than set it --- tasks/docker-users.yml | 1 + tasks/main.yml | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tasks/docker-users.yml b/tasks/docker-users.yml index 6b35881..fa78103 100644 --- a/tasks/docker-users.yml +++ b/tasks/docker-users.yml @@ -3,4 +3,5 @@ user: name: "{{ item }}" group: docker + append: yes with_items: "{{ docker_users }}" diff --git a/tasks/main.yml b/tasks/main.yml index 7b08d54..00cdf7f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,8 @@ --- -- include: setup-RedHat.yml +- include_tasks: setup-RedHat.yml when: ansible_os_family == 'RedHat' -- include: setup-Debian.yml +- include_tasks: setup-Debian.yml when: ansible_os_family == 'Debian' - name: Install Docker. @@ -14,8 +14,8 @@ state: started enabled: yes -- include: docker-compose.yml +- include_tasks: docker-compose.yml when: docker_install_compose -- include: docker-users.yml +- include_tasks: docker-users.yml when: docker_users From 4f1a0f3d91ae37736a258606c467a203290e0a61 Mon Sep 17 00:00:00 2001 From: James McCallum Date: Tue, 26 Sep 2017 05:14:53 +1000 Subject: [PATCH 4/5] Change include_task to depreciated include due to what looks like incompatibility with test harness --- tasks/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 00cdf7f..7b08d54 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,8 @@ --- -- include_tasks: setup-RedHat.yml +- include: setup-RedHat.yml when: ansible_os_family == 'RedHat' -- include_tasks: setup-Debian.yml +- include: setup-Debian.yml when: ansible_os_family == 'Debian' - name: Install Docker. @@ -14,8 +14,8 @@ state: started enabled: yes -- include_tasks: docker-compose.yml +- include: docker-compose.yml when: docker_install_compose -- include_tasks: docker-users.yml +- include: docker-users.yml when: docker_users From 622dc1dac736eb2b513b332a52e10b91b83f50f7 Mon Sep 17 00:00:00 2001 From: James McCallum Date: Wed, 18 Oct 2017 20:01:02 +1100 Subject: [PATCH 5/5] Update documentation --- README.md | 8 ++++---- defaults/main.yml | 2 +- tasks/docker-users.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4edabe7..91591e7 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ Docker Compose installation options. (Used only for RedHat/CentOS.) You can enable the Edge or Test repo by setting the respective vars to `1`. -Set the docker_users variable to allow those users to run docker (these users are added to the docker group) - docker_users: - - Guy - - James + - user1 + - user2 + +Set the docker_users variable to allow those users to run docker (these users are added to the docker group) ## Use with Ansible (and `docker` Python library) diff --git a/defaults/main.yml b/defaults/main.yml index 21fdbf1..cb6b312 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,5 +18,5 @@ docker_yum_repo_url: https://download.docker.com/linux/centos/docker-{{ docker_e docker_yum_repo_enable_edge: 0 docker_yum_repo_enable_test: 0 -# Docker users +# A list of users who will be added to the docker group. docker_users: [] diff --git a/tasks/docker-users.yml b/tasks/docker-users.yml index fa78103..ccc1ac7 100644 --- a/tasks/docker-users.yml +++ b/tasks/docker-users.yml @@ -1,5 +1,5 @@ --- -- name: Add users to docker group +- name: Ensure docker users are added to the docker group. user: name: "{{ item }}" group: docker