feat: replace docker_service module by systemd unit

This commit is contained in:
Adrien Waksberg 2018-12-23 11:30:26 +01:00
parent 71e4cbd246
commit 19a6c5baf1
3 changed files with 20 additions and 10 deletions

View file

@ -3,9 +3,10 @@ Description= Docker compose for %i
After=network.target docker.service After=network.target docker.service
[Service] [Service]
Type=oneshot Type=simple
ExecStart=/usr/bin/docker-compose up -d -f /etc/docker/compose/%i/docker-compose.yml ExecStart=/usr/bin/docker-compose -f /etc/docker/compose/%i/docker-compose.yml up
ExecStop=/usr/bin/docker-compose down -f /etc/docker/compose/%i/docker-compose.yml ExecReload=/usr/bin/docker-compose -f /etc/docker/compose/%i/docker-compose.yml up --no-recreate -d
Restart=always
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

5
handlers/main.yml Normal file
View file

@ -0,0 +1,5 @@
---
- name: reload docker-compose
systemd:
name: 'docker-compose@*'
state: reloaded

View file

@ -11,24 +11,28 @@
- name: copy docker-compose configuration - name: copy docker-compose configuration
copy: copy:
content: '{{ item.value|to_yaml }}' content: '{{ item.value|to_nice_yaml }}'
dest: '/etc/docker/compose/{{ item.key }}/docker-compose.yml' dest: '/etc/docker/compose/{{ item.key }}/docker-compose.yml'
owner: root owner: root
group: root group: root
mode: 0640 mode: 0640
loop: '{{ docker_services|dict2items }}' loop: '{{ docker_services|dict2items }}'
notify: reload docker-compose
no_log: true no_log: true
tags: docker tags: docker
- name: apply docker-compose configuration
docker_service:
project_src: '/etc/docker/compose/{{ item }}'
loop: '{{ docker_services|list }}'
tags: docker
- name: enable and start docker-compose - name: enable and start docker-compose
systemd: systemd:
name: 'docker-compose@{{ item }}' name: 'docker-compose@{{ item }}'
state: started
enabled: yes enabled: yes
loop: '{{ docker_services|list }}' loop: '{{ docker_services|list }}'
tags: docker tags: docker
#- name: apply docker-compose configuration
# systemd:
# name: 'docker-compose@{{ item.item.key }}'
# state: reloaded
# loop: '{{ config.results }}'
# when: item.changed
# tags: docker