feat: add labels to swarm workers

This commit is contained in:
Alexander Navarro 2024-12-10 18:52:58 -03:00
parent d318880600
commit 7a01bb6abf
5 changed files with 40 additions and 14 deletions

View file

@ -134,7 +134,7 @@
;hash_behaviour=replace
# (pathlist) Comma separated list of Ansible inventory sources
inventory=/etc/ansible/hosts,./hosts/inventory.ini
inventory=/etc/ansible/hosts,./hosts/inventory.yaml
# (pathspec) Colon separated paths in which Ansible will search for HttpApi Plugins.
;httpapi_plugins=/home/aleidk/.ansible/plugins/httpapi:/usr/share/ansible/plugins/httpapi

View file

@ -1,12 +0,0 @@
[homelab:children]
docker
[docker:children]
docker_managers
docker_workers
[docker_managers]
10.0.10.50
[docker_workers]
10.0.10.[51:52]

21
hosts/inventory.yaml Normal file
View file

@ -0,0 +1,21 @@
homelab:
children:
docker:
docker:
children:
docker_managers:
docker_workers:
docker_managers:
hosts:
10.0.10.50:
docker_workers:
hosts:
10.0.10.51:
node_labels:
services_kind: projects
10.0.10.52:
node_labels:
services_kind: common

View file

@ -0,0 +1,11 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/refs/heads/main/src/ansiblelint/schemas/playbook.json
---
- name: Deploy homelab services
hosts: 10.0.10.50
tasks:
- name: Deploy RSS Feed
community.docker.docker_stack:
state: present
name: rss
compose:
- files/docker/stack-rss.yml

View file

@ -1,9 +1,15 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/ansible/ansible-lint/refs/heads/main/src/ansiblelint/schemas/tasks.json
---
- name: Join Docker Swarm as a worker
- name: Join node to swarm
vars:
key: "{{ groups[managers_group] | map('extract', hostvars, ['swarm_info', 'swarm_facts', 'JoinTokens', 'Worker']) | list | first }}"
community.docker.docker_swarm:
state: join
join_token: "{{ key }}"
remote_addrs: "{{ groups[managers_group] | map('extract', hostvars, ['ansible_default_ipv4', 'address']) }}"
- name: Set node labels
delegate_to: "{{ groups[managers_group] | first }}"
community.docker.docker_node:
hostname: "{{ ansible_hostname }}"
labels: "{{ node_labels }}"