| 1 |
- name: Collect facts on the storage array |
| 2 |
na_santricity_facts: |
| 3 |
ssid: "{{ current_eseries_ssid }}" |
| 4 |
api_url: "{{ current_eseries_api_url }}" |
| 5 |
api_username: "{{ current_eseries_api_username }}" |
| 6 |
api_password: "{{ current_eseries_api_password }}" |
| 7 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 8 |
connection: local |
| 9 |
register: storage_array_facts |
| 10 |
|
| 11 |
- name: Collect volume host and host group list |
| 12 |
set_fact: |
| 13 |
hosts_definition: "{{ lookup('netapp_eseries.santricity.santricity_host', hostvars[inventory_hostname], |
| 14 |
volumes=lookup('netapp_eseries.santricity.santricity_volume', hostvars[inventory_hostname])) }}" |
| 15 |
|
| 16 |
- name: Retrieve required details and map luns |
| 17 |
block: |
| 18 |
- name: Collect host/host group networking information |
| 19 |
setup: |
| 20 |
gather_subset: min |
| 21 |
register: hosts_info |
| 22 |
delegate_to: "{{ item }}" |
| 23 |
delegate_facts: True |
| 24 |
loop: "{{ lookup('list', (hosts_definition['expected_hosts'].keys() | list)) }}" |
| 25 |
|
| 26 |
- name: Collect Ansible defined host and host group interface information |
| 27 |
set_fact: |
| 28 |
host_interface_ansible: |- |
| 29 |
{%- set host_interfaces = [] -%} |
| 30 |
{%- for host in (hosts_definition['expected_hosts'].keys() | list) -%} |
| 31 |
{%- if "eseries_iscsi_iqn" in (hostvars[host].keys() | list) -%} |
| 32 |
{%- if host_interfaces.append({"item": host, "stdout_lines": [hostvars[host]["eseries_iscsi_iqn"]]}) -%}{%- endif -%} |
| 33 |
{%- elif "eseries_nvme_nqn" in (hostvars[host].keys() | list) -%} |
| 34 |
{%- if host_interfaces.append({"item": host, "stdout_lines": [hostvars[host]["eseries_nvme_nqn"]]}) -%}{%- endif -%} |
| 35 |
{%- endif -%} |
| 36 |
{%- endfor -%} |
| 37 |
{{ host_interfaces }} |
| 38 |
|
| 39 |
- name: Collect host and host group interface information for Linux |
| 40 |
shell: "{{ eseries_initiator_command[eseries_initiator_protocol]['linux'] }}" |
| 41 |
register: host_interface_linux |
| 42 |
delegate_to: "{{ item }}" |
| 43 |
become: True |
| 44 |
changed_when: False |
| 45 |
failed_when: "host_interface_linux.rc != 0 and not (eseries_initiator_protocol in eseries_protocols_using_eseries_iscsi_iqn or |
| 46 |
eseries_initiator_protocol in eseries_protocols_using_eseries_nvme_nqn)" |
| 47 |
when: '((hostvars[item]["ansible_facts"]["system"] | lower) == "linux" and |
| 48 |
("eseries_iscsi_iqn" not in (hostvars[item].keys() | list) or eseries_initiator_protocol not in eseries_protocols_using_eseries_iscsi_iqn) and |
| 49 |
("eseries_nvme_nqn" not in (hostvars[item].keys() | list) or eseries_initiator_protocol not in eseries_protocols_using_eseries_nvme_nqn))' |
| 50 |
loop: "{{ lookup('list', (hosts_definition['expected_hosts'].keys() | list)) }}" |
| 51 |
|
| 52 |
- name: Collect host and host group interface information for Windows |
| 53 |
win_shell: "{{ eseries_initiator_command[eseries_initiator_protocol]['windows'] }}" |
| 54 |
register: host_interface_windows |
| 55 |
delegate_to: "{{ item }}" |
| 56 |
changed_when: False |
| 57 |
failed_when: "host_interface_windows.rc != 0" |
| 58 |
when: '((hostvars[item]["ansible_facts"]["os_family"] | lower == "windows") and |
| 59 |
("eseries_iscsi_iqn" not in (hostvars[item].keys() | list) or eseries_initiator_protocol not in eseries_protocols_using_eseries_iscsi_iqn) and |
| 60 |
("eseries_nvme_nqn" not in (hostvars[item].keys() | list) or eseries_initiator_protocol not in eseries_protocols_using_eseries_nvme_nqn))' |
| 61 |
loop: "{{ lookup('list', (hosts_definition['expected_hosts'].keys() | list)) }}" |
| 62 |
|
| 63 |
- name: Aggregate host/host group interface information |
| 64 |
set_fact: |
| 65 |
host_interface: |- |
| 66 |
{%- set host_interfaces = [] -%} |
| 67 |
{%- for host in (hosts_definition['expected_hosts'].keys() | list) -%} |
| 68 |
{%- set found_interfaces = host_interface_ansible + host_interface_linux['results'] + host_interface_windows['results'] -%} |
| 69 |
{%- for interface in found_interfaces if interface["item"] == host and "skip_reason" not in (interface.keys() | list) and interface["stdout_lines"] -%} |
| 70 |
{%- if host_interfaces.append(interface) -%}{%- endif -%} |
| 71 |
{%- else -%} |
| 72 |
{%- if eseries_initiator_protocol in eseries_protocols_using_eseries_iscsi_iqn -%} |
| 73 |
{%- if host_interfaces.append({"item": host, "stdout_lines": [eseries_iscsi_iqn_prefix ~ hostvars[host]["ansible_machine_id"][-12:]], "generate": True}) -%}{%- endif -%} |
| 74 |
{%- elif eseries_initiator_protocol in eseries_protocols_using_eseries_nvme_nqn -%} |
| 75 |
{%- if host_interfaces.append({"item": host, "stdout_lines": [eseries_nvme_nqn_prefix ~ hostvars[host]["ansible_machine_id"]], "generate": True}) -%}{%- endif -%} {%- endif -%} |
| 76 |
{%- endfor -%} |
| 77 |
{%- endfor -%} |
| 78 |
{{- host_interfaces -}} |
| 79 |
|
| 80 |
- name: Generate missing host IQN (Linux only). |
| 81 |
block: |
| 82 |
- name: Ensure path for initiatorname.iscsi exists. |
| 83 |
file: |
| 84 |
state: directory |
| 85 |
path: "{{ eseries_iscsi_iqn_path }}" |
| 86 |
delegate_to: "{{ item['item'] }}" |
| 87 |
become: true |
| 88 |
loop: "{{ host_interface }}" |
| 89 |
when: "(hostvars[item['item']]['ansible_facts']['system'] | lower) == 'linux' and (item['generate'] | default(False)) == True" |
| 90 |
- name: Generate initiatorname.iscsi file. |
| 91 |
ansible.builtin.template: |
| 92 |
src: initiatorname_iscsi.j2 |
| 93 |
dest: "{{ eseries_iscsi_iqn_path }}initiatorname.iscsi" |
| 94 |
delegate_to: "{{ item['item'] }}" |
| 95 |
become: true |
| 96 |
loop: "{{ host_interface }}" |
| 97 |
when: "(hostvars[item['item']]['ansible_facts']['system'] | lower) == 'linux' and (item['generate'] | default(False)) == True" |
| 98 |
when: eseries_initiator_protocol in eseries_protocols_using_eseries_iscsi_iqn |
| 99 |
|
| 100 |
- name: Generate missing host NQN (Linux only). |
| 101 |
block: |
| 102 |
- name: Ensure NVMe NQN directory exists on host. |
| 103 |
file: |
| 104 |
state: directory |
| 105 |
path: "{{ eseries_nvme_nqn_path }}" |
| 106 |
delegate_to: "{{ item['item'] }}" |
| 107 |
become: true |
| 108 |
loop: "{{ host_interface }}" |
| 109 |
when: "(hostvars[item['item']]['ansible_facts']['system'] | lower) == 'linux' and (item['generate'] | default(False)) == True" |
| 110 |
- name: Generate NVMe NQN for host if one was not discovered. |
| 111 |
ansible.builtin.template: |
| 112 |
src: hostnqn.j2 |
| 113 |
dest: "{{ eseries_nvme_nqn_path }}hostnqn" |
| 114 |
delegate_to: "{{ item['item'] }}" |
| 115 |
become: true |
| 116 |
loop: "{{ host_interface }}" |
| 117 |
when: "(hostvars[item['item']]['ansible_facts']['system'] | lower) == 'linux' and (item['generate'] | default(False)) == True" |
| 118 |
when: eseries_initiator_protocol in eseries_protocols_using_eseries_nvme_nqn |
| 119 |
|
| 120 |
- name: Organize host/host group interface information and update hosts variable |
| 121 |
set_fact: |
| 122 |
hosts_definition: "{{ lookup('netapp_eseries.santricity.santricity_host_detail', |
| 123 |
hosts_definition, hosts_info=hosts_info['results'], host_interface_ports=host_interface, protocol=eseries_initiator_protocol) }}" |
| 124 |
|
| 125 |
- name: "{{'Create' if (eseries_remove_all_configuration_state | default('present')) == 'present' else 'Delete' }} all hosts objects on the storage array" |
| 126 |
na_santricity_host: |
| 127 |
ssid: "{{ current_eseries_ssid }}" |
| 128 |
api_url: "{{ current_eseries_api_url }}" |
| 129 |
api_username: "{{ current_eseries_api_username }}" |
| 130 |
api_password: "{{ current_eseries_api_password }}" |
| 131 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 132 |
state: "{{ eseries_remove_all_configuration_state | default(hosts_definition['expected_hosts'][item]['state'] | default(omit)) }}" |
| 133 |
name: "{{ hosts_definition['expected_hosts'][item]['sanitized_hostname'] }}" |
| 134 |
ports: "{{ hosts_definition['expected_hosts'][item]['ports'] }}" |
| 135 |
force_port: "{{ eseries_host_force_port | default(omit) }}" |
| 136 |
host_type: "{{ hosts_definition['expected_hosts'][item]['host_type'] | default(omit) }}" |
| 137 |
connection: local |
| 138 |
loop: "{{ lookup('list', (hosts_definition['expected_hosts'].keys()|list)) }}" |
| 139 |
|
| 140 |
- name: "{{'Create' if (eseries_remove_all_configuration_state | default('present')) == 'present' else 'Delete' }} all required host groups on the storage array" |
| 141 |
na_santricity_hostgroup: |
| 142 |
ssid: "{{ current_eseries_ssid }}" |
| 143 |
api_url: "{{ current_eseries_api_url }}" |
| 144 |
api_username: "{{ current_eseries_api_username }}" |
| 145 |
api_password: "{{ current_eseries_api_password }}" |
| 146 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 147 |
state: "{{ eseries_remove_all_configuration_state | default('present') }}" |
| 148 |
name: "{{ item }}" |
| 149 |
hosts: "{{ hosts_definition['host_groups'][item] | default(omit) }}" |
| 150 |
connection: local |
| 151 |
loop: "{{ lookup('list', (hosts_definition['host_groups'].keys()|list)) }}" |
| 152 |
|
| 153 |
- name: Update facts on the storage array |
| 154 |
na_santricity_facts: |
| 155 |
ssid: "{{ current_eseries_ssid }}" |
| 156 |
api_url: "{{ current_eseries_api_url }}" |
| 157 |
api_username: "{{ current_eseries_api_username }}" |
| 158 |
api_password: "{{ current_eseries_api_password }}" |
| 159 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 160 |
connection: local |
| 161 |
register: storage_array_facts |
| 162 |
when: eseries_remove_all_configuration_state is not defined or eseries_remove_all_configuration_state == False |
| 163 |
|
| 164 |
- name: "{{'Map' if (eseries_remove_all_configuration_state | default('present')) == 'present' else 'Unmap' }} volume to host or host group." |
| 165 |
na_santricity_lun_mapping: |
| 166 |
ssid: "{{ current_eseries_ssid }}" |
| 167 |
api_url: "{{ current_eseries_api_url }}" |
| 168 |
api_username: "{{ current_eseries_api_username }}" |
| 169 |
api_password: "{{ current_eseries_api_password }}" |
| 170 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 171 |
state: "{{ 'present' if item['target'] is defined else 'absent' }}" |
| 172 |
volume: "{{ item['volume'] }}" |
| 173 |
target: "{{ item['target'] | default(eseries_lun_mapping_host) | default(omit) }}" |
| 174 |
lun: "{{ item['lun'] | default(omit) }}" |
| 175 |
connection: local |
| 176 |
loop: "{{ lookup('netapp_eseries.santricity.santricity_lun_mapping', storage_array_facts, |
| 177 |
volumes=lookup('netapp_eseries.santricity.santricity_volume', hostvars[inventory_hostname]), wantlist=True) }}" |
| 178 |
when: hosts_definition != [] |