feat: add docker networks

This commit is contained in:
Adrien Waksberg 2019-03-17 22:43:20 +01:00
parent 19a6c5baf1
commit 3dd6da701f
6 changed files with 37 additions and 9 deletions

View file

@ -11,6 +11,14 @@ Install and configure docker service
## Role variables
* `docker_compose_version` - set the docker-compose version to install (default: `1.23.2`)
* `docker_networks` - array with the docker networks
```
- name: workgroup
subnet: 192.168.0.0/24
gateway: 192.168.0.1
```
* `docker_services` - hash with the docker-compose configuration (see [docker documentation](https://docs.docker.com/compose/compose-file/compose-file-v2/#service-configuration-reference))
```

View file

@ -2,3 +2,4 @@
docker_compose_version: 1.23.2
docker_compose_url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
docker_services: {}
docker_networks: []

View file

@ -10,6 +10,11 @@
- software-properties-common
tags: docker
- name: install docker-py
pip:
name: docker-py
tags: docker
- name: add gpg key for docker repository
apt_key:
url: https://download.docker.com/linux/debian/gpg

View file

@ -1,4 +1,13 @@
---
- name: create networks
docker_network:
name: '{{ item.name }}'
ipam_options:
subnet: '{{ item.subnet }}'
gateway: '{{ item.gateway }}'
loop: '{{ docker_networks }}'
tags: docker
- name: create docker-compose folders
file:
path: '/etc/docker/compose/{{ item }}'
@ -28,11 +37,3 @@
enabled: yes
loop: '{{ docker_services|list }}'
tags: docker
#- name: apply docker-compose configuration
# systemd:
# name: 'docker-compose@{{ item.item.key }}'
# state: reloaded
# loop: '{{ config.results }}'
# when: item.changed
# tags: docker

View file

@ -2,9 +2,17 @@
- hosts: default
connection: local
vars:
docker_networks:
- name: workgroup
subnet: 192.168.1.0/24
gateway: 192.168.1.1
docker_services:
test:
version: '2'
version: '2.4'
networks:
default:
external:
name: workgroup
services:
test:
image: alpine:latest

View file

@ -20,6 +20,11 @@ describe file('/etc/docker/compose/test/docker-compose.yml') do
it { should contain '/bin/sleep infinity' }
end
describe command('docker network list') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'workgroup' }
end
describe command('docker ps') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match 'alpine' }