docker.portainer/tasks/main.yml

66 lines
1.9 KiB
YAML

---
# tasks file for portainer role
#
# Set up the admin password
#
- name: Make sure htpasswd is installed
apt:
name: apache2-utils
state: present
when: inventory_hostname == server_host and server_host and server_host != "none"
- name: Create bcrypt password
shell:
cmd: |
htpasswd -nb -B admin "{{ portainer_password }}" | cut -d ":" -f 2
register: portainer_password_bcrypt
when: inventory_hostname == server_host and server_host and server_host != "none"
#
# Install portainer server on the server host
#
- name: Skip server installation
debug:
msg: "Skip server installation because server_host is {{ server_host }}"
when: server_host == "none"
#
# Install portainer server on the server host
#
- name: Install server
docker_container:
name: "portainer_{{ inventory_hostname }}"
hostname: "portainer_{{ inventory_hostname}}"
domainname: "{{ domain_suffix }}"
image: "portainer/portainer-ce"
recreate: yes
restart: yes
restart_policy: "always"
ports:
- "{{ portainer_port}}:8000"
- "9000:9000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "{{ portainer_config }}:/data"
command: [ "--admin-password", "'{{ portainer_password_bcrypt.stdout }}'"]
when: inventory_hostname == server_host and server_host and server_host != "none"
#
# Install portainer server on the server host
#
- name: Install agent
docker_container:
name: "portainer_agent_{{ inventory_hostname }}"
hostname: "portainer_agent_{{ inventory_hostname}}"
domainname: "{{ domain_suffix }}"
image: "portainer/agent"
recreate: yes
restart: yes
restart_policy: "always"
ports:
- "9001:9001"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/var/lib/docker/volumes:/var/lib/docker/volumes"
when: inventory_hostname != server_host and server_host