main.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. # Copyright 2020 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: Give slurm user permission to slurmctld spool
  16. file:
  17. path: "{{ spool_slurmctld_pth }}"
  18. owner: slurm
  19. group: slurm
  20. mode: "{{ tmp_mode }}"
  21. state: touch
  22. - name: Give slurm ownership to cluster state
  23. file:
  24. path: "{{ cluster_state_path }}"
  25. owner: slurm
  26. group: slurm
  27. mode: "{{ tmp_mode }}"
  28. state: touch
  29. - name: Create slurmctld log file on master
  30. file:
  31. path: "{{ slurm_logpth }}"
  32. owner: slurm
  33. mode: "{{ tmp_mode }}"
  34. state: touch
  35. with_items:
  36. - slurmctld.log
  37. - name: Create log files on master
  38. file:
  39. path: "{{ slurm_logpth }}"
  40. owner: slurm
  41. mode: "{{ tmp_mode }}"
  42. state: touch
  43. with_items:
  44. - "{{ log_files_master }}"
  45. - name: Get mariadb password from vault
  46. command: ansible-vault view {{ input_config_pth }} --vault-password-file {{ vault_path }}
  47. register: vault_contents
  48. delegate_to: localhost
  49. changed_when: true
  50. - name: Extract db password from input config file
  51. set_fact:
  52. db_password="{{ vault_contents.stdout | regex_findall('[\n\r].*mariadb_password:\s*\"([^\n\r]*)\"') }}"
  53. - name: Install packages for slurm
  54. package:
  55. name: "{{ item }}"
  56. state: present
  57. with_items:
  58. - "{{ slurm_packages }}"
  59. tags: install
  60. - name: Install development tools
  61. package:
  62. name: "{{ item }}"
  63. state: present
  64. with_items:
  65. - "{{ dev_tools }}"
  66. tags: install
  67. - name: Create temporary download folder for slurm
  68. file:
  69. path: "{{ tmp_path }}"
  70. owner: slurm
  71. group: slurm
  72. mode: "{{ tmp_mode }}"
  73. state: directory
  74. - name: Download slurm source
  75. get_url:
  76. url: "{{ slurm_url }}"
  77. dest: "{{ tmp_path }}"
  78. checksum: "{{ slurm_md5 }}"
  79. validate_certs: no
  80. tags: install
  81. - name: Build slurm rpms
  82. command: rpmbuild -ta "{{ rpmbuild_path }}" --with mysql
  83. changed_when: false
  84. args:
  85. warn: no
  86. - name: Verify package md5
  87. command: rpm -qa
  88. ignore_errors: true
  89. register: verify_result
  90. changed_when: no
  91. failed_when: no
  92. args:
  93. warn: no
  94. - name: Install rpms
  95. command: rpm -Uvh ~"{{ rpm_loop }}"
  96. args:
  97. chdir: "{{ rpm_path }}"
  98. warn: no
  99. changed_when: true
  100. - name: Get the hostname
  101. command: hostname -s
  102. register: machine_name
  103. changed_when: true
  104. - name: Add control machine name
  105. lineinfile:
  106. path: "{{ slurm_confpth }}"
  107. regexp: "ControlMachine="
  108. line: "ControlMachine={{ machine_name.stdout }}"
  109. - name: Add slurm user name
  110. lineinfile:
  111. path: "{{ slurm_confpth }}"
  112. regexp: "SlurmUser="
  113. line: "SlurmUser={{ slurm_user }}"
  114. - name: Install firewalld
  115. package:
  116. name: firewalld
  117. state: present
  118. tags: firewalld
  119. - name: Start and enable firewalld
  120. service:
  121. name: firewalld
  122. state: started
  123. enabled: yes
  124. tags: firewalld
  125. - name: Firewall rule for slurm - tcp/udp ports
  126. firewalld:
  127. zone: public
  128. port: "{{ item }}"
  129. permanent: true
  130. state: enabled
  131. with_items:
  132. - "{{ tcp_port1 }}"
  133. - "{{ tcp_port2 }}"
  134. - "{{ tcp_port3 }}"
  135. - "{{ udp_port3 }}"
  136. - "{{ udp_port1 }}"
  137. - "{{ udp_port2 }}"
  138. when: "'manager' in group_names"
  139. tags: firewalld
  140. - name: Get network address/subnet mask through ipaddr
  141. set_fact:
  142. network_address: "{{ (ansible_default_ipv4.network + '/' + ansible_default_ipv4.netmask) | ipaddr('network/prefix') }}"
  143. - name: Firewall rule slurm - allow all incoming traffic on internal network
  144. firewalld:
  145. zone: internal
  146. rich_rule: 'rule family="{{ family }}" source address="{{ network_address }}" accept'
  147. permanent: true
  148. state: enabled
  149. tags: firewalld
  150. - name: Reload firewalld
  151. command: firewall-cmd --reload
  152. changed_when: true
  153. tags: firewalld
  154. - name: Start mariadb
  155. systemd:
  156. name: mariadb
  157. state: restarted
  158. enabled: yes
  159. tags: install
  160. - name: Grant permissions for slurm db
  161. command: mysql -u root -e "GRANT ALL ON slurm_acct_db.* TO '{{ db_user }}'@'{{ db_host }}' identified by '{{ db_password[0] }}'with grant option;"
  162. tags: install
  163. changed_when: true
  164. - name: Create slurmdbd.conf file
  165. copy:
  166. src: slurmdbd.conf
  167. dest: "{{ slurmdbd_path }}"
  168. mode: "{{ slurmdbd_mode }}"
  169. owner: slurm
  170. tags: install
  171. - name: Add slurm user name
  172. lineinfile:
  173. path: "{{ slurmdbd_path }}"
  174. regexp: "SlurmUser="
  175. line: "SlurmUser={{ slurm_user }}"
  176. - name: Add db address
  177. lineinfile:
  178. path: "{{ slurmdbd_path }}"
  179. regexp: "DbdAddr="
  180. line: "DbdAddr={{ DbdAddr }}"
  181. - name: Add db host
  182. lineinfile:
  183. path: "{{ slurmdbd_path }}"
  184. regexp: "DbdHost="
  185. line: "DbdHost={{ DbdHost }}"
  186. - name: Add storage password
  187. lineinfile:
  188. path: "{{ slurmdbd_path }}"
  189. regexp: "StoragePass="
  190. line: "StoragePass={{ db_password[0] }}"
  191. - name: Add storage user
  192. lineinfile:
  193. path: "{{ slurmdbd_path }}"
  194. regexp: "StorageUser="
  195. line: "StorageUser={{ slurm_user }}"
  196. - name: Add log file path
  197. lineinfile:
  198. path: "{{ slurmdbd_path }}"
  199. regexp: "LogFile="
  200. line: "LogFile={{ logfile }}"
  201. - name: Add pid file path
  202. lineinfile:
  203. path: "{{ slurmdbd_path }}"
  204. regexp: "PidFile="
  205. line: "PidFile={{ pidfile }}"
  206. - name: Save slurm conf file in buffer
  207. fetch:
  208. src: "{{ slurm_confpth }}"
  209. dest: "{{ buffer_path }}"
  210. flat: true