Skip to content

Commit

Permalink
Fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Jun 24, 2018
1 parent 71cda5f commit 42872d8
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed

- Role is not idempotent for Ubuntu and Debian distributions ([#41](../../issues/41))
- Cannot set hosts in daemon.json because of arguments to dockerd in Ubuntu/Debian ([#42](../../issues/42))

## [1.6.0](../../releases/tag/1.6.0) - 2018-06-07

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Variables related to this role are listed below:
# docker_daemon_config:
# experimental: true
docker_daemon_config:
# Docker daemon options
# Docker daemon is configured with '-H fd://' by default in Ubuntu/Debian which cause problems.
# https://github.com/moby/moby/issues/25471
docker_daemon_opts: ''
# To compensate for situation where Docker daemon fails because of usermod incompatibility.
# Ensures that 'dockremap:500000:65536' is present in /etc/subuid and /etc/subgid.
# Note! If userns-remap is set to 'default' in docker_daemon_config this config will be unnecessary.
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
# docker_daemon_config:
# experimental: true
docker_daemon_config:
# Docker daemon options
# Docker daemon is configured with '-H fd://' by default in Ubuntu/Debian which cause problems.
# https://github.com/moby/moby/issues/25471
docker_daemon_opts: ''
# To compensate for situation where Docker daemon fails because of usermod incompatibility.
# Ensures that 'dockremap:500000:65536' is present in /etc/subuid and /etc/subgid.
# Note! If userns-remap is set to 'default' in docker_daemon_config this config will be unnecessary.
Expand Down
4 changes: 0 additions & 4 deletions files/etc/systemd/system/docker.service.d/docker-storage.conf

This file was deleted.

30 changes: 30 additions & 0 deletions tasks/configure-drop-ins.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- name: Ensure /etc/systemd/system/docker.service.d directory exists
file:
path: /etc/systemd/system/docker.service.d
state: directory
mode: 0755
become: yes

- name: Setup default Docker drop-in to enable use of environment file
template:
src: drop-ins/default.conf.j2
dest: /etc/systemd/system/docker.service.d/default.conf
become: yes
register: systemd_docker_dropin
vars:
systemd_envs_dir: "{{ docker_systemd_envs_dir[_docker_os_dist] }}"

- name: Setup Docker environment file {{ docker_systemd_envs_dir[_docker_os_dist] }}/docker-envs
template:
src: docker-envs.j2
dest: "{{ docker_systemd_envs_dir[_docker_os_dist] }}/docker-envs"
become: yes
register: systemd_docker_env
vars:
docker_opts: "{{ docker_daemon_opts }}"

- name: Force daemon reload of systemd
systemd:
daemon_reload: yes
become: yes
when: systemd_docker_dropin|changed or systemd_docker_env|changed
7 changes: 0 additions & 7 deletions tasks/kernel-3-mount-fixes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
become: yes
when: may_detach_mounts.stat.exists

- name: Ensure /etc/systemd/system/docker.service.d directory exists
file:
path: /etc/systemd/system/docker.service.d
state: directory
mode: 0755
become: yes

- name: Copy systemd drop-in for Docker Mount Flags slave configuration to avoid 'Device or resource busy'
copy:
src: files/etc/systemd/system/docker.service.d/mountflags-slave.conf
Expand Down
3 changes: 3 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
- include_tasks: setup-audit.yml
tags: ["configure"]

- include_tasks: configure-drop-ins.yml
tags: ["configure"]

- include_tasks: kernel-3-mount-fixes.yml
when: ansible_kernel | version_compare('4', '<')
tags: ["configure"]
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
_docker_os_dist == "CentOS" or
_docker_os_dist == "RedHat"

- name: Add Docker’s official GPG key
- name: Add Docker official GPG key
apt_key:
url: https://download.docker.com/linux/{{ _docker_os_dist|lower }}/gpg
state: present
Expand Down
1 change: 1 addition & 0 deletions templates/docker-envs.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOCKER_OPTS='{{ docker_opts }}'
4 changes: 4 additions & 0 deletions templates/drop-ins/default.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Service]
EnvironmentFile=-{{ systemd_envs_dir }}/docker-envs
ExecStart=
ExecStart=/usr/bin/dockerd $DOCKER_OPTS
11 changes: 11 additions & 0 deletions tests/test_issue_42.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- hosts: test-host
vars:
docker_daemon_config:
hosts:
# fd:// does not work in CentOS
- unix:///var/run/docker.sock
- tcp://0.0.0.0:2376
init: true
roles:
- haxorof.docker-ce
56 changes: 37 additions & 19 deletions tests/vagrant_config.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
configs:
use: 'centos'
centos_no_docker:
use: 'defaults_centos'
# No Docker installed
no_docker_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_nothing.yml
centos:
# Older Docker test
old_docker_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_old_version.yml
# Role default tests
defaults_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_defaults.yml
defaults_ubuntu_trusty:
box: 'geerlingguy/ubuntu1404'
prep_yml: prepare.yml
test_yml: test_defaults.yml
centos_config:
defaults_debian_jessie:
box: 'geerlingguy/debian8'
prep_yml: prepare.yml
test_yml: test_defaults.yml
# Config tests
config_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_config.yml
centos_storage:
# Storage testing
config_storage_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare_storage.yml
test_yml: test_config_storage.yml
centos_old_docker:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_old_version.yml
ubuntu_trusty:
box: 'geerlingguy/ubuntu1404'
prep_yml: prepare.yml
test_yml: test_config.yml
ubuntu_xenial:
config_storage_ubuntu_xenial:
box: 'geerlingguy/ubuntu1604'
prep_yml: prepare_storage.yml
test_yml: test_config_storage.yml
debian_jessie:
box: 'geerlingguy/debian8'
prep_yml: prepare.yml
test_yml: test_config.yml
debian_stretch:
config_storage_debian_stretch:
box: 'geerlingguy/debian9'
prep_yml: prepare_storage.yml
test_yml: test_config_storage.yml
# Issue testing
issue_42_ubuntu_xenial:
box: 'geerlingguy/ubuntu1604'
prep_yml: prepare.yml
test_yml: test_issue_42.yml
issue_42_debian_stretch:
box: 'geerlingguy/debian9'
prep_yml: prepare.yml
test_yml: test_issue_42.yml
issue_42_centos:
box: 'geerlingguy/centos7'
prep_yml: prepare.yml
test_yml: test_issue_42.yml
7 changes: 7 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ docker_cmd_update_repo_cache:
Ubuntu: apt-get update
Debian: apt-get update

docker_systemd_envs_dir:
CentOS: /etc/sysconfig
RedHat: /etc/sysconfig
Fedora: /etc/sysconfig
Ubuntu: /etc/default
Debian: /etc/default

docker_old_packages:
CentOS:
- docker
Expand Down

0 comments on commit 42872d8

Please sign in to comment.