|
| 1 | +- name: Check if slurm database has been initialised |
| 2 | + # DB is initialised on the first slurmdbd startup (without -u option). |
| 3 | + # If it is not initialised, `slurmdbd -u` errors with something like |
| 4 | + # > Slurm Database is somehow higher than expected '4294967294' but I only |
| 5 | + # > know as high as '16'. Conversion needed. |
| 6 | + community.mysql.mysql_query: |
| 7 | + login_db: "{{ openhpc_slurmdbd_mysql_database }}" |
| 8 | + login_user: "{{ openhpc_slurmdbd_mysql_username }}" |
| 9 | + login_password: "{{ openhpc_slurmdbd_mysql_password }}" |
| 10 | + login_host: "{{ openhpc_slurmdbd_host }}" |
| 11 | + query: SHOW TABLES |
| 12 | + config_file: '' |
| 13 | + register: _openhpc_slurmdb_tables |
| 14 | + |
| 15 | +- name: Check if slurm database requires an upgrade |
| 16 | + ansible.builtin.command: slurmdbd -u |
| 17 | + register: _openhpc_slurmdbd_check |
| 18 | + changed_when: false |
| 19 | + failed_when: >- |
| 20 | + _openhpc_slurmdbd_check.rc > 1 or |
| 21 | + 'Slurm Database is somehow higher than expected' in _openhpc_slurmdbd_check.stdout |
| 22 | + # from https://github.com/SchedMD/slurm/blob/master/src/plugins/accounting_storage/mysql/as_mysql_convert.c |
| 23 | + when: _openhpc_slurmdb_tables.query_result | flatten | length > 0 # i.e. when db is initialised |
| 24 | + |
| 25 | +- name: Set fact for slurm database upgrade |
| 26 | + # Explanation of ifs below: |
| 27 | + # - `slurmdbd -u` rc == 0 then no conversion required (from manpage) |
| 28 | + # - default of 0 on rc skips upgrade steps if check was skipped because |
| 29 | + # db is not initialised |
| 30 | + # - Usage message (and rc == 1) if -u option doesn't exist, in which case |
| 31 | + # it can't be a major upgrade due to existing openhpc versions |
| 32 | + set_fact: |
| 33 | + _openhpc_slurmdb_upgrade: >- |
| 34 | + {{ false |
| 35 | + if ( |
| 36 | + ( _openhpc_slurmdbd_check.rc | default(0) == 0) |
| 37 | + or |
| 38 | + ( 'Usage: slurmdbd' in _openhpc_slurmdbd_check.stderr ) |
| 39 | + ) else |
| 40 | + true |
| 41 | + }} |
| 42 | +
|
| 43 | +- name: Ensure Slurm database service stopped |
| 44 | + ansible.builtin.systemd: |
| 45 | + name: "{{ openhpc_slurm_accounting_storage_service }}" |
| 46 | + state: stopped |
| 47 | + register: _openhpc_slurmdb_state |
| 48 | + when: |
| 49 | + - _openhpc_slurmdb_upgrade |
| 50 | + - openhpc_slurm_accounting_storage_service != '' |
| 51 | + |
| 52 | +- name: Backup Slurm database |
| 53 | + ansible.builtin.shell: # noqa: command-instead-of-shell |
| 54 | + cmd: "{{ openhpc_slurm_accounting_storage_backup_cmd }}" |
| 55 | + delegate_to: "{{ openhpc_slurm_accounting_storage_backup_host }}" |
| 56 | + become: "{{ openhpc_slurm_accounting_storage_backup_become }}" |
| 57 | + changed_when: true |
| 58 | + run_once: true |
| 59 | + when: |
| 60 | + - _openhpc_slurmdb_upgrade |
| 61 | + - openhpc_slurm_accounting_storage_backup_cmd != '' |
| 62 | + |
| 63 | +- name: Ensure Slurm database service started |
| 64 | + ansible.builtin.systemd: |
| 65 | + name: "{{ openhpc_slurm_accounting_storage_service }}" |
| 66 | + state: started |
| 67 | + when: |
| 68 | + - openhpc_slurm_accounting_storage_service != '' |
| 69 | + - _openhpc_slurmdb_state.changed | default(false) |
| 70 | + |
| 71 | +- name: Run slurmdbd in foreground for upgrade |
| 72 | + ansible.builtin.expect: |
| 73 | + command: /usr/sbin/slurmdbd -D -vvv |
| 74 | + responses: |
| 75 | + (?i)Everything rolled up: |
| 76 | + # See https://wiki.fysik.dtu.dk/Niflheim_system/Slurm_installation/#upgrade-slurmdbd |
| 77 | + # and |
| 78 | + # https://github.com/SchedMD/slurm/blob/0ce058c5adcf63001ec2ad211c65e67b0e7682a8/src/plugins/accounting_storage/mysql/as_mysql_usage.c#L1042 |
| 79 | + become: true |
| 80 | + become_user: slurm |
| 81 | + when: _openhpc_slurmdb_upgrade |
0 commit comments