nfs_node_configure.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # Copyright 2022 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: Include
  16. include_tasks: "{{ pv_ports_file }}"
  17. - name: Refresh ssh keys
  18. command: ssh-keygen -R {{ groups['powervault_me4'][0] }}
  19. changed_when: false
  20. tags: install
  21. failed_when: false
  22. - name: Validate authentication of username and password
  23. command: ping -c1 {{ groups['powervault_me4'][0] }}
  24. register: validate_login
  25. changed_when: false
  26. failed_when: false
  27. - name: NFS node configuration on leap
  28. block:
  29. - name: Install open-iscsi
  30. zypper:
  31. name: open-iscsi
  32. state: present
  33. tags: install
  34. - name: Install sg3_utils
  35. zypper:
  36. name: sg3_utils
  37. state: present
  38. tags: install
  39. - name: Start the iSCSI deamon
  40. systemd:
  41. name: iscsid
  42. state: started
  43. - block:
  44. - name: Configure nic
  45. command: ip a add {{ pv_nic_ip }}/255.255.255.0 dev {{ pv_nic }}
  46. register: nic_status
  47. changed_when: false
  48. rescue:
  49. - name: Check if nic configured or not
  50. fail:
  51. msg: "{{ nic_conf_failed_msg }}"
  52. when: nic_status_search not in nic_status.stderr
  53. - name: Up the nic
  54. command: ip link set dev {{ pv_nic }} up
  55. changed_when: false
  56. when: os_supported_leap in ansible_distribution | lower
  57. - name: NFS node configuration on rocky
  58. block:
  59. - name: Install packages
  60. package:
  61. name: iscsi-initiator-utils
  62. state: present
  63. tags: install
  64. - name: Install packages
  65. package:
  66. name: sg3_utils
  67. state: present
  68. tags: install
  69. - name: Set bootproto value
  70. lineinfile:
  71. path: "{{ nic_path }}"
  72. regexp: '^BOOTPROTO='
  73. line: 'BOOTPROTO=none'
  74. register: result
  75. - name: Set onboot value
  76. lineinfile:
  77. path: "{{ nic_path }}"
  78. regexp: '^ONBOOT='
  79. line: 'ONBOOT=yes'
  80. - name: Add ip address
  81. lineinfile:
  82. path: "{{ nic_path }}"
  83. insertafter: '^ONBOOT=yes'
  84. line: 'IPADDR={{ pv_nic_ip }}'
  85. - name: Add netmask address
  86. lineinfile:
  87. path: "{{ nic_path }}"
  88. insertafter: '^IPADDR={{ pv_nic_ip }}'
  89. line: NETMASK=255.255.255.0
  90. - name: Down the nic
  91. command: ifdown {{ pv_nic }}
  92. changed_when: true
  93. failed_when: false
  94. tags: install
  95. - name: Up the nic
  96. command: ifup {{ pv_nic }}
  97. changed_when: true
  98. tags: install
  99. - name: Show ip
  100. shell: >
  101. set -o pipefail && \
  102. ifconfig {{ pv_nic }} | grep 'inet' |cut -d: -f2 | awk '{ print $2}'
  103. changed_when: false
  104. when: os_supported_leap not in ansible_distribution | lower
  105. - name: Discover nodes
  106. command: iscsiadm -m discovery -t sendtargets -p {{ item }}
  107. with_items: "{{ set_port_ip }}"
  108. register: ports_available
  109. failed_when: false
  110. changed_when: false
  111. tags: install
  112. - name: Pv port ip
  113. add_host:
  114. name: pv
  115. map_ip: "{{ item.item }}"
  116. with_items: "{{ ports_available.results }}"
  117. when: item.rc == 0
  118. - name: Pv port ip
  119. set_fact:
  120. map_ip_output: "{{ item.stdout_lines }}"
  121. with_items: "{{ ports_available.results }}"
  122. when: item.rc == 0
  123. - name: Find feasible port ip
  124. set_fact:
  125. discover: "{{ item }}"
  126. with_items: "{{ map_ip_output }}"
  127. when: hostvars['pv']['map_ip'] in item
  128. - name: Split on comma
  129. set_fact:
  130. ip_port: "{{ discover.split(',')[0] }}"
  131. - name: Pv name
  132. set_fact:
  133. pv_name: "{{ discover.split(',')[1].split()[1] }}"
  134. - name: IQDN id
  135. shell: >
  136. set -o pipefail && \
  137. grep "InitiatorName=" /etc/iscsi/initiatorname.iscsi | cut -f2 -d"="
  138. register: iqdn_id
  139. changed_when: false
  140. tags: install
  141. - name: Add ME4 volume data to dummy host
  142. add_host:
  143. name: "server_iqdn_id"
  144. server_iqdn: "{{ iqdn_id.stdout }}"
  145. - name: Login to the powervault
  146. command: iscsiadm -m node --login {{ pv_name }} -p {{ ip_port }}
  147. changed_when: true
  148. failed_when: false
  149. tags: install