65 lines
1.5 KiB
YAML
65 lines
1.5 KiB
YAML
---
|
|
- name: Wait for Cloud-init to finish
|
|
hosts: all
|
|
gather_facts: no
|
|
roles:
|
|
- cloudinit_wait
|
|
|
|
- name: Initialize Docker Swarm nodes
|
|
hosts: all
|
|
pre_tasks:
|
|
- name: Delete externally managed environment file
|
|
shell:
|
|
cmd: "rm /usr/lib/python*/EXTERNALLY-MANAGED"
|
|
register: rm
|
|
changed_when: "rm.rc == 0"
|
|
failed_when: "false"
|
|
|
|
- name: Create data directories
|
|
file:
|
|
state: directory
|
|
path: "{{ data_directory_base }}/{{ item }}"
|
|
recurse: true
|
|
mode: 0777
|
|
loop: "{{ data_directories }}"
|
|
|
|
roles:
|
|
- setup_apt
|
|
- docker
|
|
|
|
- name: Setup Docker Swarm manager
|
|
hosts: manager
|
|
tasks:
|
|
- name: Install pip packages
|
|
pip:
|
|
name:
|
|
- jsondiff
|
|
- pyyaml
|
|
|
|
- name: Create Docker Swarm
|
|
docker_swarm:
|
|
|
|
- name: Get Docker Swarm manager info
|
|
docker_swarm_info:
|
|
nodes: yes
|
|
nodes_filters:
|
|
name: manager
|
|
register: swarm_info
|
|
|
|
- hosts: workers
|
|
tasks:
|
|
- name: Join Docker Swarm
|
|
docker_swarm:
|
|
state: join
|
|
join_token: "{{ hostvars.manager.swarm_info.swarm_facts.JoinTokens.Worker }}"
|
|
remote_addrs:
|
|
- "{{ hostvars.manager.ansible_default_ipv4.address }}"
|
|
|
|
- hosts: manager
|
|
tasks:
|
|
- name: Add labels to Docker Swarm
|
|
docker_node:
|
|
hostname: "{{ item.hostname }}"
|
|
labels: "{{ item.labels }}"
|
|
labels_state: replace
|
|
loop: "{{ docker_node_labels }}"
|