Create swarm
This commit is contained in:
17
hosts
17
hosts
@@ -8,13 +8,22 @@ gitea ansible_host=10.0.0.212 hypervisor=rack1 memory=1024 cpus=2
|
||||
[developer-machines]
|
||||
codydev ansible_host=10.0.0.207 hypervisor=rack2 memory=2048 cpus=2
|
||||
|
||||
[swarm-bootstrap]
|
||||
swarm-manager-01 ansible_host=10.0.0.206 hypervisor=rack1 memory=2048 cpus=2
|
||||
|
||||
[swarm-managers]
|
||||
swarm-manager-02 ansible_host=10.0.0.225 hypervisor=rack2 memory=2048 cpus=2
|
||||
swarm-manager-03 ansible_host=10.0.0.220 hypervisor=rack2 memory=2048 cpus=2
|
||||
|
||||
[swarm-workers]
|
||||
swarm-worker-01 ansible_host=10.0.0.208 hypervisor=rack2 memory=2048 cpus=2
|
||||
swarm-worker-02 ansible_host=10.0.0.213 hypervisor=rack1 memory=2048 cpus=2
|
||||
swarm-worker-03 ansible_host=10.0.0.214 hypervisor=rack1 memory=2048 cpus=2
|
||||
|
||||
|
||||
[need-converted]
|
||||
#vpn ansible_host=10.0.0.203 hypervisor=rack1 memory=1024 cpus=2
|
||||
#haproxy ansible_host=10.0.0.205 hypervisor=rack2 memory=1024 cpus=2
|
||||
#swarm-manager-01 ansible_host=10.0.0.206 hypervisor=rack1 memory=2048 cpus=2
|
||||
#swarm-manager-02 ansible_host=10.0.0.225 hypervisor=rack2 memory=2048 cpus=2
|
||||
#swarm-manager-03 ansible_host=10.0.0.220 hypervisor=rack2 memory=2048 cpus=2
|
||||
#swarm-worker-01 ansible_host=10.0.0.208 hypervisor=rack2 memory=2048 cpus=2
|
||||
#registry ansible_host=10.0.0.221 hypervisor=rack1 memory=2048 cpus=2
|
||||
#wrestlingdev-test ansible_host=10.0.0.240 hypervisor=rack1 memory=2048 cpus=2
|
||||
#elk ansible_host=10.0.0.224 hypervisor=rack2 memory=4096 cpus=2
|
||||
|
||||
@@ -25,3 +25,45 @@
|
||||
serial: 100%
|
||||
tasks:
|
||||
- include: ../roles/developer-machine/tasks/main.yml
|
||||
|
||||
- name: Initialize the swarm
|
||||
hosts: swarm-bootstrap
|
||||
user: root
|
||||
gather_facts: true
|
||||
serial: 100%
|
||||
vars:
|
||||
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
||||
tasks:
|
||||
- include_tasks: ../tasks/swarm-bootstrap.yml
|
||||
|
||||
- name: Add additional managers to the swarm
|
||||
hosts: swarm-managers
|
||||
user: root
|
||||
gather_facts: false
|
||||
serial: 100%
|
||||
vars:
|
||||
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
||||
vars:
|
||||
join_addr:
|
||||
"{{ hostvars[groups['swarm-bootstrap'][0]].ansible_eth0.ipv4.address }}"
|
||||
manager_key:
|
||||
"{{ hostvars[groups['swarm-bootstrap'][0]]['manager_key']['stdout'] }}"
|
||||
tasks:
|
||||
- include_tasks: ../tasks/swarm-manager.yml
|
||||
|
||||
|
||||
- name: Add workers to the swarm
|
||||
hosts: swarm-workers
|
||||
user: root
|
||||
gather_facts: false
|
||||
serial: 100%
|
||||
vars:
|
||||
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
|
||||
vars:
|
||||
join_addr:
|
||||
"{{ hostvars[groups['swarm-bootstrap'][0]].ansible_eth0.ipv4.address }}"
|
||||
worker_key:
|
||||
"{{ hostvars[groups['swarm-bootstrap'][0]]['worker_key']['stdout'] }}"
|
||||
tasks:
|
||||
- include_tasks: ../tasks/swarm-worker.yml
|
||||
|
||||
|
||||
22
tasks/swarm-bootstrap.yml
Normal file
22
tasks/swarm-bootstrap.yml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- name: Initialize swarm on the bootstrap manager
|
||||
command: >
|
||||
docker swarm init --advertise-addr "{{ ansible_eth0.ipv4.address }}"
|
||||
register: docker_swarm_init
|
||||
changed_when: docker_swarm_init.rc == 0
|
||||
ignore_errors: true
|
||||
|
||||
- name: Set manager key variable
|
||||
command: docker swarm join-token -q manager
|
||||
register: manager_key
|
||||
changed_when: manager_key.rc == 0
|
||||
|
||||
- name: Set worker key variable
|
||||
command: docker swarm join-token -q worker
|
||||
register: worker_key
|
||||
changed_when: worker_key.rc == 0
|
||||
|
||||
- name: Set work and manager key facts
|
||||
set_fact:
|
||||
manager_key: "{{ manager_key }}"
|
||||
worker_key: "{{ worker_key }}"
|
||||
6
tasks/swarm-manager.yml
Normal file
6
tasks/swarm-manager.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
- name: Add swarm managers to the cluster
|
||||
command: >
|
||||
docker swarm join --token "{{ manager_key }}" "{{ join_addr }}":2377
|
||||
register: docker_swarm_join
|
||||
changed_when: docker_swarm_join.rc == 0
|
||||
ignore_errors: true
|
||||
6
tasks/swarm-worker.yml
Normal file
6
tasks/swarm-worker.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
- name: Add swarm workers to the cluster
|
||||
command: >
|
||||
docker swarm join --token "{{ worker_key }}" "{{ join_addr }}":2377
|
||||
register: docker_swarm_join
|
||||
changed_when: docker_swarm_join.rc == 0
|
||||
ignore_errors: true
|
||||
Reference in New Issue
Block a user