mirror of
https://github.com/luzifer-ansible/docker-compose.git
synced 2024-12-22 17:01:17 +00:00
Initial import as galaxy role
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
commit
5c9615fd2b
5 changed files with 189 additions and 0 deletions
13
README.md
Normal file
13
README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# luzifer-ansible / docker-compose
|
||||||
|
|
||||||
|
This role installs latest docker-compose on a host and start it as a systemd daemon (it does not take care about installing Docker itself so this needs to be done before by some other role or external functionality.)
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Debian >= 8 (jessie)
|
||||||
|
- Ubuntu >= 16.04 (xenial)
|
||||||
|
- Docker
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
See the [Ansible Galaxy Intro](https://galaxy.ansible.com/intro) for usage of roles within Ansible Galaxy.
|
7
defaults/main.yml
Normal file
7
defaults/main.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
reload_minutes: 15
|
||||||
|
|
||||||
|
config:
|
||||||
|
version: "3"
|
||||||
|
services:
|
41
meta/main.yml
Normal file
41
meta/main.yml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
---
|
||||||
|
galaxy_info:
|
||||||
|
author: Knut Ahlers
|
||||||
|
description: |
|
||||||
|
Install latest docker-compose on a host and start it as a systemd
|
||||||
|
daemon (it does not take care about installing Docker itself so
|
||||||
|
this needs to be done before by some other role or external
|
||||||
|
functionality.)
|
||||||
|
|
||||||
|
license: Apache
|
||||||
|
min_ansible_version: 2.3
|
||||||
|
|
||||||
|
platforms:
|
||||||
|
- name: Ubuntu
|
||||||
|
versions:
|
||||||
|
- xenial
|
||||||
|
- name: Debian
|
||||||
|
versions:
|
||||||
|
- jessie
|
||||||
|
- stretch
|
||||||
|
|
||||||
|
categories:
|
||||||
|
#- cloud
|
||||||
|
#- cloud:ec2
|
||||||
|
#- cloud:gce
|
||||||
|
#- cloud:rax
|
||||||
|
#- clustering
|
||||||
|
#- database
|
||||||
|
#- database:nosql
|
||||||
|
#- database:sql
|
||||||
|
#- development
|
||||||
|
#- monitoring
|
||||||
|
#- networking
|
||||||
|
#- packaging
|
||||||
|
- system
|
||||||
|
#- web
|
||||||
|
|
||||||
|
dependencies: []
|
||||||
|
# List your role dependencies here, one per line.
|
||||||
|
# Be sure to remove the '[]' above if you add dependencies
|
||||||
|
# to this list.
|
125
tasks/main.yml
Normal file
125
tasks/main.yml
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
# Install docker-compose
|
||||||
|
|
||||||
|
- name: Ensure pip to be available
|
||||||
|
apt:
|
||||||
|
name: python-pip
|
||||||
|
update_cache: yes
|
||||||
|
|
||||||
|
- name: Install or update docker-compose
|
||||||
|
pip:
|
||||||
|
name: docker-compose
|
||||||
|
state: latest
|
||||||
|
register: docker_compose
|
||||||
|
|
||||||
|
# Configure docker-compose
|
||||||
|
|
||||||
|
- name: Create configuration directory
|
||||||
|
file:
|
||||||
|
dest: /etc/docker-compose
|
||||||
|
state: directory
|
||||||
|
mode: 0700
|
||||||
|
|
||||||
|
- name: Write docker-compose.yml
|
||||||
|
template:
|
||||||
|
dest: /etc/docker-compose/docker-compose.yml
|
||||||
|
src: templates/docker-compose.yml
|
||||||
|
mode: 0600
|
||||||
|
register: compose_file
|
||||||
|
|
||||||
|
- name: Validate configuration
|
||||||
|
command: docker-compose config -q
|
||||||
|
args:
|
||||||
|
chdir: /etc/docker-compose
|
||||||
|
when: compose_file.changed
|
||||||
|
|
||||||
|
# Install and start services
|
||||||
|
|
||||||
|
- name: Install docker-compose.service
|
||||||
|
copy:
|
||||||
|
dest: /etc/systemd/system/docker-compose.service
|
||||||
|
content: |
|
||||||
|
[Unit]
|
||||||
|
Description=Docker Compose container starter
|
||||||
|
After=docker.service network-online.target
|
||||||
|
Requires=docker.service network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=/etc/docker-compose
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
|
||||||
|
ExecStartPre=/usr/local/bin/docker-compose pull --quiet --parallel --ignore-pull-failures
|
||||||
|
ExecStart=/usr/local/bin/docker-compose up -d
|
||||||
|
|
||||||
|
ExecStop=/usr/local/bin/docker-compose down
|
||||||
|
|
||||||
|
ExecReload=/usr/local/bin/docker-compose pull --quiet --parallel --ignore-pull-failures
|
||||||
|
ExecReload=/usr/local/bin/docker-compose up -d
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
register: docker_compose_service
|
||||||
|
|
||||||
|
- name: Start and enable docker-compose service
|
||||||
|
systemd:
|
||||||
|
name: docker-compose.service
|
||||||
|
daemon_reload: yes
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: Restart service if service configuration changed
|
||||||
|
systemd:
|
||||||
|
name: docker-compose.service
|
||||||
|
daemon_reload: yes
|
||||||
|
state: restarted
|
||||||
|
when: docker_compose_service.changed
|
||||||
|
|
||||||
|
- name: Reload and apply configuration
|
||||||
|
systemd:
|
||||||
|
name: docker-compose.service
|
||||||
|
state: reloaded
|
||||||
|
when: docker_compose.changed or compose_file.changed
|
||||||
|
|
||||||
|
- name: Install docker-compose-reload.service
|
||||||
|
copy:
|
||||||
|
dest: /etc/systemd/system/docker-compose-reload.service
|
||||||
|
content: |
|
||||||
|
[Unit]
|
||||||
|
Description=Refresh images and update containers
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
|
||||||
|
ExecStart=/bin/systemctl reload docker-compose.service
|
||||||
|
|
||||||
|
- name: Install docker-compose-reload.timer
|
||||||
|
copy:
|
||||||
|
dest: /etc/systemd/system/docker-compose-reload.timer
|
||||||
|
content: |
|
||||||
|
[Unit]
|
||||||
|
Description=Refresh images and update containers
|
||||||
|
Requires=docker-compose.service
|
||||||
|
After=docker-compose.service
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*:0/{{ reload_minutes }}
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
register: docker_compose_reload_timer
|
||||||
|
|
||||||
|
- name: Enable and start docker-compose-reload.timer
|
||||||
|
systemd:
|
||||||
|
name: docker-compose-reload.timer
|
||||||
|
daemon_reload: yes
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: Restart docker-compose-reload.timer if it changed
|
||||||
|
systemd:
|
||||||
|
name: docker-compose-reload.timer
|
||||||
|
daemon_reload: yes
|
||||||
|
state: restarted
|
||||||
|
when: docker_compose_reload_timer.changed
|
3
templates/docker-compose.yml
Normal file
3
templates/docker-compose.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
|
{{ config | to_nice_yaml }}
|
Loading…
Reference in a new issue