---
- name: Install slurm packages
  ansible.builtin.yum:
    name: "{{ item }}"
    state: present
  loop:
    - munge
    - "slurm-client-{{ slurm_version }}"

- name: Create slurm group
  ansible.builtin.group:
    name: slurm
    state: present
    gid: 450

- name: Create slurm user
  ansible.builtin.user:
    name: slurm
    state: present
    uid: 450
    group: slurm
    create_home: false

- name: Copy munge key
  ansible.builtin.copy:
    src: munge.key
    dest: /etc/munge/munge.key
    owner: daemon
    group: root
    mode: 0400

- name: Create symbolic links for Slurm config files
  ansible.builtin.file:
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
    state: link
    force: yes  # Force the creation of the symlinks even if source files do not exist yet
  loop:
    - { src: "/cm/shared/apps/slurm/var/etc/cgroup.conf", dest: "/etc/slurm/cgroup.conf" }
    - { src: "/cm/shared/apps/slurm/var/etc/gres.conf", dest: "/etc/slurm/gres.conf" }
    - { src: "/cm/shared/apps/slurm/var/etc/slurm.conf", dest: "/etc/slurm/slurm.conf" }
    - { src: "/cm/shared/apps/slurm/var/etc/slurmdbd.conf", dest: "/etc/slurm/slurmdbd.conf" }

- name: Enable services
  ansible.builtin.service:
    name: "{{ item }}"
    enabled: yes
  loop:
    - munge
    - slurmd
