mount_me4_partitions.yml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # Copyright 2021 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. - name: Get ME4 volume
  16. shell: >
  17. set -o pipefail && \
  18. lsscsi -s | grep ME4
  19. changed_when: false
  20. register: me4_output
  21. failed_when: false
  22. - name: ME4 volume check
  23. fail:
  24. msg: "{{ me4_volume_fail_msg }}"
  25. when: me4_output is failed or (me4_output.stdout | regex_findall('ME4') | length) != 2
  26. - name: Set ME4 data facts
  27. set_fact:
  28. me4_k8s_volume_data: "{{ me4_output.stdout.split('\n')[0].split(' ') | select() }}"
  29. me4_slurm_volume_data: "{{ me4_output.stdout.split('\n')[1].split(' ') | select() }}"
  30. - name: Add ME4 volume data to dummy host
  31. add_host:
  32. name: "NFS_NODE_TOKEN_HOLDER"
  33. me4_k8s_volume: "{{ me4_k8s_volume_data[-2] }}"
  34. me4_slurm_volume: "{{ me4_slurm_volume_data[-2] }}"
  35. - name: Get all mounted partitions
  36. command: df -h
  37. changed_when: false
  38. register: mounted_partitions
  39. - name: Create partition on ME4 volumes
  40. command: "parted -a optimal {{ item }} --script -- mklabel gpt mkpart primary 0% {{ powervault_me4_disk_partition_size }}"
  41. changed_when: true
  42. with_items:
  43. - "{{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_k8s_volume'] }}"
  44. - "{{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_slurm_volume'] }}"
  45. when:
  46. - hostvars['NFS_NODE_TOKEN_HOLDER']['me4_k8s_volume'] not in mounted_partitions.stdout
  47. - hostvars['NFS_NODE_TOKEN_HOLDER']['me4_slurm_volume'] not in mounted_partitions.stdout
  48. - name: Update kernel with new partition changes
  49. command: partprobe
  50. changed_when: false
  51. - name: Check ME4 mounted partitions
  52. shell: >
  53. set -o pipefail && \
  54. mount | grep me4
  55. failed_when: false
  56. changed_when: false
  57. args:
  58. warn: false
  59. register: me4_mounted_partitions
  60. - name: Set file system on partition
  61. shell: >
  62. set -o pipefail && \
  63. echo y | mkfs -t ext4 {{ item }}1
  64. with_items:
  65. - "{{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_k8s_volume'] }}"
  66. - "{{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_slurm_volume'] }}"
  67. when:
  68. - me4_nfs_share_k8s not in me4_mounted_partitions.stdout
  69. - me4_nfs_share_slurm not in me4_mounted_partitions.stdout
  70. - name: Creating NFS share directories
  71. file:
  72. path: "{{ item }}"
  73. state: directory
  74. mode: "{{ nfs_share_dir_mode }}"
  75. with_items:
  76. - "{{ me4_nfs_share_k8s }}"
  77. - "{{ me4_nfs_share_slurm }}"
  78. - name: Mount K8s partition on K8s NFS share
  79. command: "mount {{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_k8s_volume'] }}1 {{ me4_nfs_share_k8s }}"
  80. changed_when: true
  81. args:
  82. warn: false
  83. when: me4_nfs_share_k8s not in me4_mounted_partitions.stdout
  84. - name: Mount Slurm partition on Slurm NFS share
  85. command: "mount {{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_slurm_volume'] }}1 {{ me4_nfs_share_slurm }}"
  86. changed_when: true
  87. args:
  88. warn: false
  89. when: me4_nfs_share_slurm not in me4_mounted_partitions.stdout
  90. - name: Configuring auto mount K8s partition on reboot
  91. lineinfile:
  92. path: "{{ fstab_file_path }}"
  93. line: "{{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_k8s_volume'] }}1 {{ me4_nfs_share_k8s }} ext4 defaults 0 0"
  94. - name: Configuring auto mount Slurm partition on reboot
  95. lineinfile:
  96. path: "{{ fstab_file_path }}"
  97. line: "{{ hostvars['NFS_NODE_TOKEN_HOLDER']['me4_slurm_volume'] }}1 {{ me4_nfs_share_slurm }} ext4 defaults 0 0"