diff --git a/library/roles/docker/defaults/main.yml b/library/roles/docker/defaults/main.yml index fcf1aac9..49c53c08 100644 --- a/library/roles/docker/defaults/main.yml +++ b/library/roles/docker/defaults/main.yml @@ -30,5 +30,6 @@ docker_user_home: /home/docker docker_defaults_file: /etc/default/docker docker_enable_tcp_socket: False docker_tcp_socket_port: 2375 +docker_api_port: 2376 docker_tcp_socket_host: 127.0.0.1 diff --git a/library/roles/docker/tasks/pkgs.yml b/library/roles/docker/tasks/pkgs.yml index b15aebef..857476a8 100644 --- a/library/roles/docker/tasks/pkgs.yml +++ b/library/roles/docker/tasks/pkgs.yml @@ -19,8 +19,27 @@ - name: Install the Docker default options template: src=docker-default.j2 dest={{ docker_defaults_file }} owner=root group=root mode=0644 + when: ansible_service_mgr != 'systemd' notify: Restart docker + - name: Create the docker service systemd directory + file: dest=/etc/systemd/system/docker.service.d state=directory mode=0755 + when: ansible_service_mgr == 'systemd' + tags: [ 'docker', 'docker_systemd' ] + + - name: Install the Docker additional systemd unit + template: src=docker-systemd-override.conf.j2 dest=/etc/systemd/system/docker.service.d/override.conf owner=root group=root mode=0644 + when: ansible_service_mgr == 'systemd' + notify: Restart docker + register: reload_systemd + tags: [ 'docker', 'docker_systemd' ] + + - name: systemd reload + command: systemctl daemon-reload + when: reload_systemd is defined and reload_systemd is changed + tags: [ 'docker', 'docker_systemd' ] + + - name: Ensure that the service is started and enabled service: name=docker state=started enabled=yes diff --git a/library/roles/docker/templates/docker-systemd-override.conf.j2 b/library/roles/docker/templates/docker-systemd-override.conf.j2 new file mode 100644 index 00000000..8b5dc317 --- /dev/null +++ b/library/roles/docker/templates/docker-systemd-override.conf.j2 @@ -0,0 +1,7 @@ +[Service] +ExecStart= +{% if docker_swarm %} +ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:{{ docker_api_port }} -H fd:// --containerd=/run/containerd/containerd.sock +{% else %} +ExecStart=/usr/bin/dockerd {% if docker_enable_tcp_socket %} -H tcp://{{ docker_tcp_socket_host }}:{{ docker_tcp_socket_port }} {% endif %} -H fd:// --containerd=/run/containerd/containerd.sock +{% endif %} \ No newline at end of file