-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
swarm.yml
116 lines (110 loc) · 3.24 KB
/
swarm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
- name: Recreate the swarm hosts
hosts: localhost
vars_files:
- vars/devlab-pve.yml
- vaults/vault.yml
- vars/swarm.yml
tasks:
- name: Purge the old containers
ansible.builtin.include_role:
name: pve_purge
vars:
vmid: '{{ item.vmid }}'
when: recreate
loop: '{{ swarm_managers + swarm_workers }}'
- name: Create the containers
ansible.builtin.include_role:
name: pve_lxc_create
vars:
vmid: '{{ item.vmid }}'
hostname: '{{ item.hostname }}'
pve_lxc_networks: '{{ item.pve_lxc_networks }}'
pve_lxc_ostemplate: '{{ item.pve_lxc_ostemplate | default("local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst") }}'
when: recreate
loop: '{{ swarm_managers + swarm_workers }}'
- name: Enable ssh on Fedora hosts
hosts: devlab_pve
vars_files:
- vars/devlab-pve.yml
- vars/swarm.yml
tasks:
- name: Enable ssh
ansible.builtin.include_role:
name: pve_lxc_enable_sshd
vars:
vmid: '{{ host.vmid }}'
when: recreate and 'fedora' in (host.pve_lxc_ostemplate | default(''))
loop: '{{ swarm_managers + swarm_workers }}'
loop_control:
loop_var: host
- name: Install docker
hosts:
- swarm_managers
- swarm_workers
vars_files:
- vaults/vault.yml
- vars/swarm.yml
vars:
base_dev_user: false
base_ansible_user: false
roles:
- role: base
when: recreate
- role: docker
when: recreate
- role: ssl_server
vars:
ssl_server_cert_path: /etc/certs
ssl_server_cert_name: '{{ ansible_hostname }}'
ssl_server_user: root
ssl_server_group: root
ssl_server_subject_alt_names:
- '{{ ansible_fqdn }}'
when: recreate
- name: Initialize the swarm
hosts: swarm_primary_manager
tasks:
- name: Initialize the primary manager
community.docker.docker_swarm:
state: present
register: swarm_result
- name: Save the tokens
ansible.builtin.set_fact:
manager_token: '{{ swarm_result.swarm_facts.JoinTokens.Manager }}'
worker_token: '{{ swarm_result.swarm_facts.JoinTokens.Worker }}'
cachable: true
- name: Add the managers
hosts: swarm_other_managers
tasks:
- name: Add the other managers to the swarm
community.docker.docker_swarm:
state: join
remote_addrs:
- 192.168.100.131
join_token: "{{ hostvars['192.168.100.131']['manager_token'] }}"
- name: Add the worker hosts
hosts: swarm_workers
tasks:
- name: Add the other managers to the swarm
community.docker.docker_swarm:
state: join
join_token: "{{ hostvars['192.168.100.131']['worker_token'] }}"
remote_addrs:
- 192.168.100.131
- 192.168.100.132
- name: Test by installing chatbot-ollama
hosts: swarm_primary_manager
tasks:
- name: Install chatbot-ollama
community.docker.docker_swarm_service:
name: chatbot-ollama
image: ghcr.io/ivanfioravanti/chatbot-ollama:main
replicas: 1
publish:
- published_port: 3000
target_port: 3000
protocol: tcp
mode: host
mode: global
env:
OLLAMA_HOST=http://192.168.1.50:11434