Manage the portainer network completely outside of the compose file.

This commit is contained in:
Andrea Dell'Amico 2020-10-08 14:50:07 +02:00
parent 96371e6f1d
commit 9f95f8c36d
3 changed files with 21 additions and 13 deletions

View File

@ -17,7 +17,7 @@ docker_swarm_portainer_hostname: 'portainer-swarm.example.com'
docker_swarm_portainer_additional_constraints: []
# - 'node.hostname != docker01'
docker_swarm_portainer_network: 'agent_network'
docker_swarm_portainer_network: 'portainer_agent_network'
docker_swarm_portainer_http_port: '9000'
docker_swarm_portainer_service_port: '8000'

View File

@ -1,22 +1,34 @@
---
- name: Manage the installation of portainer as a stack
block:
- name: Install the portainer docker stack configuration
template: src=portainer-agent-stack.yml.j2 dest=/srv/portainer-agent-stack.yml owner=root group=root mode='0444'
- name: Create a directory for the portainer stack
file: dest=/srv/portainer state=directory mode='0755'
- name: Create the overlay network that will be used by portainer
docker_network:
name: 'portainer_{{ docker_swarm_portainer_network }}'
driver: overlay
scope: swarm
- name: Install the portainer docker stack configuration
template: src=portainer-agent-stack.yml.j2 dest=/srv/portainer/portainer-agent-stack.yml owner=root group=root mode='0444'
- name: Run the docker stack to start portainer
docker_stack:
state: present
name: portainer
compose:
- /srv/portainer-agent-stack.yml
- /srv/portainer/portainer-agent-stack.yml
run_once: True
- name: Create the overlay network that will be used by portainer
docker_network:
name: '{{ docker_swarm_portainer_network }}'
driver: overlay
scope: swarm
- name: Connect the portainer service to its network
shell: docker service update --network-add {{ docker_swarm_portainer_network }} {{ item }} --update-delay 30s --update-parallelism 1 && touch /srv/portainer/.network_{{ item }}
with_items:
- 'portainer_portainer'
- 'portainer_agent'
args:
creates: '/srv/portainer/.network_{{ item }}'
ignore_errors: True
when: docker_swarm_manager_main_node | bool
tags: [ 'portainer', 'docker_portainer', 'docker_swarm', 'docker' ]

View File

@ -6,8 +6,6 @@ services:
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /var/lib/docker/volumes:/var/lib/docker/volumes
networks:
- 'portainer_{{ docker_swarm_portainer_network }}'
deploy:
mode: global
placement:
@ -25,8 +23,6 @@ services:
# - "{{ docker_swarm_portainer_service_port }}:8000"
volumes:
- portainer_data:/data
networks:
- 'portainer_{{ docker_swarm_portainer_network }}'
deploy:
mode: replicated
replicas: 1