logic for admin partition adn qos

This commit is contained in:
dvosler 2025-02-26 13:51:17 -05:00
parent 925aec8a17
commit 80e7a64579
1 changed files with 64 additions and 14 deletions

View File

@ -42,7 +42,7 @@
failed_when: false failed_when: false
- name: Set cluster fact if only one cluster is found - name: Set cluster fact if only one cluster is found
set_fact: ansible.builtin.set_fact:
slurm_cluster_name: "{{ cluster_list.stdout_lines[0] }}" slurm_cluster_name: "{{ cluster_list.stdout_lines[0] }}"
when: cluster_list.stdout_lines | length == 1 when: cluster_list.stdout_lines | length == 1
@ -106,6 +106,51 @@
register: user_creation_result register: user_creation_result
failed_when: user_creation_result.rc != 0 failed_when: user_creation_result.rc != 0
- name: Check existing partition associations
ansible.builtin.command: >
sacctmgr -Pn show assoc where user={{ item.username }} cluster={{ slurm_cluster_name }} account={{ item.sponsor | default('orcd') }} format=Partition,QOS,DefaultQOS
register: assoc_check
loop: "{{ slurm_qos_users }}"
loop_control:
label: "{{ item.username }}"
when: user_list.stdout is search(item.username)
changed_when: false
failed_when: false
- name: Ensure partition associations exist for existing users
ansible.builtin.command: >
sacctmgr -i add user name={{ item.0.username }}
cluster={{ slurm_cluster_name }}
account={{ item.0.sponsor | default('orcd') }}
partition={{ item.1.name }}
{% if item.1.name == 'admin' %}
QOS=admin_qos DefaultQOS=admin_qos
{% endif %}
loop: "{{ slurm_qos_users | subelements('partitions') }}"
loop_control:
label: "{{ item.0.username }} - {{ item.1.name }}"
when:
- user_list.stdout is search(item.0.username)
- assoc_check.results | selectattr('item.username', 'equalto', item.0.username) | map(attribute='stdout') | first | default('') is not search(item.1.name)
changed_when: true
- name: Update QoS for existing admin partition associations
ansible.builtin.command: >
sacctmgr -i modify user where
name={{ item.0.username }}
cluster={{ slurm_cluster_name }}
account={{ item.0.sponsor | default('orcd') }}
partition={{ item.1.name }}
set QOS=admin_qos DefaultQOS=admin_qos
loop: "{{ slurm_qos_users | subelements('partitions') }}"
loop_control:
label: "{{ item.0.username }} - {{ item.1.name }}"
when:
- user_list.stdout is search(item.0.username)
- item.1.name == 'admin'
- assoc_check.results | selectattr('item.username', 'equalto', item.0.username) | map(attribute='stdout') | first | default('') is search(item.1.name)
changed_when: true
- name: Set partition-specific node limits - name: Set partition-specific node limits
ansible.builtin.command: > ansible.builtin.command: >
sacctmgr -i modify user where sacctmgr -i modify user where
@ -114,20 +159,25 @@
account={{ item.0.sponsor | default('orcd') }} account={{ item.0.sponsor | default('orcd') }}
partition={{ item.1.name }} partition={{ item.1.name }}
set set
GrpTRES={{ item.1.grptres | default( {% if item.1.max_nodes is defined and item.1.max_nodes | int == -1 %}
slurm_qos_partition_defaults[item.1.name].grptres if item.1.name in slurm_qos_partition_defaults else GrpTRES=
'node=' + ( {% elif item.1.max_nodes is defined and item.1.max_nodes | int >= 0 %}
item.1.max_nodes | default( GrpTRES=node={{ item.1.max_nodes }}
slurm_qos_partition_defaults[item.1.name].max_nodes if item.1.name in slurm_qos_partition_defaults else {% else %}
'4' if item.1.name == 'preempt' else GrpTRES={{ item.1.grptres | default(
'2' if item.1.name == 'debug' else slurm_qos_partition_defaults[item.1.name].grptres if item.1.name in slurm_qos_partition_defaults else
'' 'node=' + (
) item.1.max_nodes | default(
) | string slurm_qos_partition_defaults[item.1.name].max_nodes if item.1.name in slurm_qos_partition_defaults else
) }} '4' if item.1.name == 'preempt' else
'2' if item.1.name == 'debug' else
'' if item.1.name == 'admin' else
''
)
) | string
) }}
{% endif %}
loop: "{{ slurm_qos_users | subelements('partitions') }}" loop: "{{ slurm_qos_users | subelements('partitions') }}"
loop_control: loop_control:
label: "{{ item.0.username }} - {{ item.1.name }}" label: "{{ item.0.username }} - {{ item.1.name }}"
changed_when: true changed_when: true
#GrpTRES={{ item.1.grptres | default(slurm_qos_partition_defaults[item.1.name].grptres if item.1.name in slurm_qos_partition_defaults else 'node=' + (item.1.max_nodes | default(slurm_qos_partition_defaults[item.1.name].max_nodes if item.1.name in slurm_qos_partition_defaults else '4' if item.1.name == 'preempt' else '2' if item.1.name == 'debug' else '')) | string) }}