yt-dlp-dags/ansible/playbook-worker.yml

101 lines
2.7 KiB
YAML

---
- name: Deploy Airflow Workers
hosts: airflow_workers
gather_facts: yes
vars_files:
- group_vars/all.yml
- group_vars/all/vault.yml
pre_tasks:
- name: Announce worker deployment
debug:
msg: "Starting deployment for Airflow Worker: {{ inventory_hostname }} ({{ ansible_host }})"
- name: Set deploy_group to a valid single group name
set_fact:
deploy_group: "ytdl"
- name: Ensure deploy group exists
group:
name: "{{ deploy_group }}"
state: present
become: yes
- name: Ensure deploy user exists
user:
name: "{{ ssh_user }}"
group: "{{ deploy_group }}"
state: present
become: yes
- name: Validate deploy_group variable
ansible.builtin.assert:
that:
- deploy_group is defined
- deploy_group is string
- "',' not in deploy_group"
- "' ' not in deploy_group"
fail_msg: "The 'deploy_group' variable ('{{ deploy_group }}') must be a single, valid group name. It should not contain commas or spaces."
- name: Check for swapfile
stat:
path: /swapfile
register: swap_file
become: yes
- name: Create 8GB swapfile
command: fallocate -l 8G /swapfile
when: not swap_file.stat.exists
become: yes
- name: Set swapfile permissions
file:
path: /swapfile
mode: '0600'
when: not swap_file.stat.exists
become: yes
- name: Make swap
command: mkswap /swapfile
when: not swap_file.stat.exists
become: yes
- name: Check current swap status
command: swapon --show
register: swap_status
changed_when: false
become: yes
- name: Enable swap
command: swapon /swapfile
when: "'/swapfile' not in swap_status.stdout"
become: yes
- name: Add swapfile to fstab
lineinfile:
path: /etc/fstab
regexp: '^/swapfile'
line: '/swapfile none swap sw 0 0'
state: present
become: yes
- name: Get GID of the deploy group
getent:
database: group
key: "{{ deploy_group }}"
register: deploy_group_info
become: yes
- name: Set deploy_group_gid fact
set_fact:
deploy_group_gid: "{{ deploy_group_info.ansible_facts.getent_group[deploy_group][1] }}"
when: deploy_group_info.ansible_facts.getent_group is defined and deploy_group in deploy_group_info.ansible_facts.getent_group
- name: Ensure deploy_group_gid is set to a valid value
set_fact:
deploy_group_gid: "0"
when: deploy_group_gid is not defined or deploy_group_gid == ""
roles:
- airflow-worker
- ytdlp-worker