diff --git a/roles/docker/defaults/main.yml b/roles/docker/defaults/main.yml new file mode 100644 index 0000000..370f7a9 --- /dev/null +++ b/roles/docker/defaults/main.yml @@ -0,0 +1,3 @@ +docker_root: /var/lib/docker-compose +docker_compose: /usr/bin/docker-compose +docker_compose_service: compose diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index f8eb230..7175650 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -4,6 +4,22 @@ state: present update_cache: true +- name: Create docker-compose root + file: + path: "{{ docker_root }}" + state: directory + +- name: Install docker-compose systemd service + template: + src: docker-compose.service.j2 + dest: "/etc/systemd/system/{{ docker_compose_service }}@.service" + register: compose_systemd + +- name: Reload systemd manager configuration + systemd: + daemon_reload: true + when: compose_systemd.changed + - name: Add users to docker group user: name: "{{ item }}" diff --git a/roles/docker/templates/docker-compose.service.j2 b/roles/docker/templates/docker-compose.service.j2 new file mode 100644 index 0000000..34e8188 --- /dev/null +++ b/roles/docker/templates/docker-compose.service.j2 @@ -0,0 +1,14 @@ +[Unit] +Description=%i docker-compose service +PartOf=docker.service +After=docker.service + +[Service] +Type=oneshot +RemainAfterExit=true +WorkingDirectory={{ docker_root }}/%i +ExecStart={{ docker_compose }} up -d --remove-orphans +ExecStop={{ docker_compose }} down + +[Install] +WantedBy=multi-user.target