feat: add docker networks
This commit is contained in:
parent
19a6c5baf1
commit
3dd6da701f
6 changed files with 37 additions and 9 deletions
|
@ -11,6 +11,14 @@ Install and configure docker service
|
||||||
## Role variables
|
## Role variables
|
||||||
|
|
||||||
* `docker_compose_version` - set the docker-compose version to install (default: `1.23.2`)
|
* `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))
|
* `docker_services` - hash with the docker-compose configuration (see [docker documentation](https://docs.docker.com/compose/compose-file/compose-file-v2/#service-configuration-reference))
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
docker_compose_version: 1.23.2
|
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_compose_url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64
|
||||||
docker_services: {}
|
docker_services: {}
|
||||||
|
docker_networks: []
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
- software-properties-common
|
- software-properties-common
|
||||||
tags: docker
|
tags: docker
|
||||||
|
|
||||||
|
- name: install docker-py
|
||||||
|
pip:
|
||||||
|
name: docker-py
|
||||||
|
tags: docker
|
||||||
|
|
||||||
- name: add gpg key for docker repository
|
- name: add gpg key for docker repository
|
||||||
apt_key:
|
apt_key:
|
||||||
url: https://download.docker.com/linux/debian/gpg
|
url: https://download.docker.com/linux/debian/gpg
|
||||||
|
|
|
@ -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
|
- name: create docker-compose folders
|
||||||
file:
|
file:
|
||||||
path: '/etc/docker/compose/{{ item }}'
|
path: '/etc/docker/compose/{{ item }}'
|
||||||
|
@ -28,11 +37,3 @@
|
||||||
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
|
|
||||||
|
|
|
@ -2,9 +2,17 @@
|
||||||
- hosts: default
|
- hosts: default
|
||||||
connection: local
|
connection: local
|
||||||
vars:
|
vars:
|
||||||
|
docker_networks:
|
||||||
|
- name: workgroup
|
||||||
|
subnet: 192.168.1.0/24
|
||||||
|
gateway: 192.168.1.1
|
||||||
docker_services:
|
docker_services:
|
||||||
test:
|
test:
|
||||||
version: '2'
|
version: '2.4'
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
external:
|
||||||
|
name: workgroup
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
image: alpine:latest
|
image: alpine:latest
|
||||||
|
|
|
@ -20,6 +20,11 @@ describe file('/etc/docker/compose/test/docker-compose.yml') do
|
||||||
it { should contain '/bin/sleep infinity' }
|
it { should contain '/bin/sleep infinity' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe command('docker network list') do
|
||||||
|
its(:exit_status) { should eq 0 }
|
||||||
|
its(:stdout) { should match 'workgroup' }
|
||||||
|
end
|
||||||
|
|
||||||
describe command('docker ps') do
|
describe command('docker ps') do
|
||||||
its(:exit_status) { should eq 0 }
|
its(:exit_status) { should eq 0 }
|
||||||
its(:stdout) { should match 'alpine' }
|
its(:stdout) { should match 'alpine' }
|
||||||
|
|
Loading…
Reference in a new issue