106 lines
3.0 KiB
YAML
106 lines
3.0 KiB
YAML
---
|
|
- name: Install and configure MariaDB for SlurmDBD
|
|
hosts: slurm_controller
|
|
become: true
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
- name: Install MariaDB and SlurmDBD packages
|
|
ansible.builtin.apt:
|
|
name:
|
|
- mariadb-server
|
|
- mariadb-client
|
|
- slurmdbd
|
|
- slurm-wlm-mysql-plugin
|
|
state: present
|
|
update_cache: true
|
|
|
|
- name: Ensure MariaDB is enabled and running
|
|
ansible.builtin.systemd:
|
|
name: mariadb
|
|
enabled: true
|
|
state: started
|
|
|
|
- name: Ensure Slurm log directory exists
|
|
ansible.builtin.file:
|
|
path: /var/log/slurm
|
|
state: directory
|
|
owner: slurm
|
|
group: slurm
|
|
mode: "0755"
|
|
|
|
- name: Create Slurm accounting database and DB user
|
|
ansible.builtin.shell: |
|
|
set -euo pipefail
|
|
mysql <<SQL
|
|
CREATE DATABASE IF NOT EXISTS {{ slurmdbd_storage_loc }};
|
|
CREATE USER IF NOT EXISTS '{{ slurmdbd_storage_user }}'@'localhost' IDENTIFIED BY '{{ slurmdbd_storage_pass }}';
|
|
CREATE USER IF NOT EXISTS '{{ slurmdbd_storage_user }}'@'127.0.0.1' IDENTIFIED BY '{{ slurmdbd_storage_pass }}';
|
|
GRANT ALL PRIVILEGES ON {{ slurmdbd_storage_loc }}.* TO '{{ slurmdbd_storage_user }}'@'localhost';
|
|
GRANT ALL PRIVILEGES ON {{ slurmdbd_storage_loc }}.* TO '{{ slurmdbd_storage_user }}'@'127.0.0.1';
|
|
FLUSH PRIVILEGES;
|
|
SQL
|
|
args:
|
|
executable: /bin/bash
|
|
changed_when: true
|
|
|
|
- name: Ensure /etc/slurm exists
|
|
ansible.builtin.file:
|
|
path: /etc/slurm
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
|
|
- name: Deploy slurmdbd.conf
|
|
ansible.builtin.template:
|
|
src: ../../templates/slurmdbd.conf.j2
|
|
dest: /etc/slurm/slurmdbd.conf
|
|
owner: slurm
|
|
group: slurm
|
|
mode: "0600"
|
|
notify:
|
|
- Restart slurmdbd
|
|
|
|
- name: Ensure slurmdbd is enabled and running
|
|
ansible.builtin.systemd:
|
|
name: slurmdbd
|
|
enabled: true
|
|
state: started
|
|
|
|
- name: Flush handlers before validation
|
|
ansible.builtin.meta: flush_handlers
|
|
|
|
- name: Validate slurmdbd service is active
|
|
ansible.builtin.command:
|
|
cmd: systemctl is-active slurmdbd
|
|
register: slurmdbd_active
|
|
retries: 10
|
|
delay: 2
|
|
until: slurmdbd_active.stdout == "active"
|
|
changed_when: false
|
|
|
|
- name: Validate slurmdbd is listening on port
|
|
ansible.builtin.shell: |
|
|
set -euo pipefail
|
|
ss -lntp | grep ':{{ slurmdbd_port }} '
|
|
args:
|
|
executable: /bin/bash
|
|
register: slurmdbd_port_check
|
|
retries: 10
|
|
delay: 2
|
|
until: slurmdbd_port_check.rc == 0
|
|
changed_when: false
|
|
|
|
- name: Show slurmdbd service validation
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "slurmdbd is active"
|
|
- "{{ slurmdbd_port_check.stdout_lines }}"
|
|
|
|
handlers:
|
|
- name: Restart slurmdbd
|
|
ansible.builtin.systemd:
|
|
name: slurmdbd
|
|
state: restarted
|