| 1 |
--- |
| 2 |
|
| 3 |
|
| 4 |
- name: Collect facts on the storage array |
| 5 |
na_santricity_facts: |
| 6 |
ssid: "{{ current_eseries_ssid }}" |
| 7 |
api_url: "{{ current_eseries_api_url }}" |
| 8 |
api_username: "{{ current_eseries_api_username }}" |
| 9 |
api_password: "{{ current_eseries_api_password }}" |
| 10 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 11 |
connection: local |
| 12 |
register: storage_array_facts |
| 13 |
when: eseries_host_object is defined |
| 14 |
|
| 15 |
- name: Organize current and expected hostgroups |
| 16 |
set_fact: |
| 17 |
current_storage_array_hostgroups: |- |
| 18 |
{%- set current_hostgroup={} %} |
| 19 |
{%- for group in storage_array_facts["storage_array_facts"]["netapp_host_groups"] %} |
| 20 |
{%- if current_hostgroup.update( {group["name"]: []} ) %}{%- endif %} |
| 21 |
{%- for host in storage_array_facts["storage_array_facts"]["netapp_hosts"] %} |
| 22 |
{%- if group["id"] == host["group_id"] and current_hostgroup[group["name"]].append(host["name"]) %}{%- endif %} |
| 23 |
{%- endfor %} |
| 24 |
{%- endfor %} |
| 25 |
{{ current_hostgroup }} |
| 26 |
hostgroups: |- |
| 27 |
{%- set hostgroups=[] %} |
| 28 |
{%- for host in eseries_host_object %} |
| 29 |
{%- if "group" in (host.keys()|list) and host["group"] not in hostgroups and |
| 30 |
("state" not in (host.keys()|list) or host["state"] == "present") and hostgroups.append(host["group"]) %} |
| 31 |
{%- endif %} |
| 32 |
{%- endfor %} |
| 33 |
{{ hostgroups }} |
| 34 |
when: eseries_host_object is defined |
| 35 |
|
| 36 |
- name: "{{'Configure' if (eseries_remove_all_configuration_state | default('present')) == 'present' else 'Unconfigure' }} inventory-defined hostgroup definitions" |
| 37 |
na_santricity_hostgroup: |
| 38 |
ssid: "{{ current_eseries_ssid }}" |
| 39 |
api_url: "{{ current_eseries_api_url }}" |
| 40 |
api_username: "{{ current_eseries_api_username }}" |
| 41 |
api_password: "{{ current_eseries_api_password }}" |
| 42 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 43 |
state: "{{ eseries_remove_all_configuration_state | default('present') }}" |
| 44 |
name: "{{ item }}" |
| 45 |
hosts: "{{ current_storage_array_hostgroups[item] | default(omit) }}" |
| 46 |
connection: local |
| 47 |
loop: "{{ lookup('list', hostgroups) }}" |
| 48 |
when: eseries_host_object is defined and (hostgroups | length > 0) |
| 49 |
|
| 50 |
- name: "{{'Configure' if (eseries_remove_all_configuration_state | default('present')) == 'present' else 'Unconfigure' }} inventory-defined host definitions" |
| 51 |
na_santricity_host: |
| 52 |
ssid: "{{ current_eseries_ssid }}" |
| 53 |
api_url: "{{ current_eseries_api_url }}" |
| 54 |
api_username: "{{ current_eseries_api_username }}" |
| 55 |
api_password: "{{ current_eseries_api_password }}" |
| 56 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 57 |
state: "{{ eseries_remove_all_configuration_state | default(item['state'] | default(omit)) }}" |
| 58 |
name: "{{ item['name'] }}" |
| 59 |
ports: "{{ item['ports'] | default(omit) }}" |
| 60 |
force_port: "{{ item['force_port'] | default(eseries_host_force_port | default(omit)) }}" |
| 61 |
group: "{{ item['group'] | default(eseries_host_group | default(omit)) }}" |
| 62 |
host_type: "{{ item['host_type_index'] | default(item['host_type'] | default(eseries_host_type_index | default(omit))) }}" |
| 63 |
connection: local |
| 64 |
loop: "{{ lookup('list', eseries_host_object) }}" |
| 65 |
when: eseries_host_object is defined |
| 66 |
|
| 67 |
- name: Collect facts on the storage array |
| 68 |
na_santricity_facts: |
| 69 |
ssid: "{{ current_eseries_ssid }}" |
| 70 |
api_url: "{{ current_eseries_api_url }}" |
| 71 |
api_username: "{{ current_eseries_api_username }}" |
| 72 |
api_password: "{{ current_eseries_api_password }}" |
| 73 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 74 |
connection: local |
| 75 |
register: storage_array_facts |
| 76 |
when: eseries_host_object is defined |
| 77 |
|
| 78 |
- name: Update the current storage array hostgroups |
| 79 |
set_fact: |
| 80 |
current_storage_array_hostgroups: |- |
| 81 |
{%- set current_hostgroup={} %} |
| 82 |
{%- for group in storage_array_facts["storage_array_facts"]["netapp_host_groups"] %} |
| 83 |
{%- if current_hostgroup.update( {group["name"]: []} ) %}{%- endif %} |
| 84 |
{%- for host in storage_array_facts["storage_array_facts"]["netapp_hosts"] %} |
| 85 |
{%- if group["id"] == host["group_id"] and current_hostgroup[group["name"]].append(host["name"]) %}{%- endif %} |
| 86 |
{%- endfor %} |
| 87 |
{%- endfor %} |
| 88 |
{{ current_hostgroup }} |
| 89 |
when: eseries_host_object is defined |
| 90 |
|
| 91 |
- name: Create list of unused hostgroups |
| 92 |
set_fact: |
| 93 |
unused_hostgroups: |- |
| 94 |
{%- set unused_hostgroup = [] %} |
| 95 |
{%- for current_host_name in (current_storage_array_hostgroups.keys()|list) %} |
| 96 |
{%- if (current_storage_array_hostgroups[current_host_name]|length==0) and unused_hostgroup.append(current_host_name) %}{%- endif %} |
| 97 |
{%- endfor %} |
| 98 |
{{ unused_hostgroup }} |
| 99 |
when: eseries_host_object is defined |
| 100 |
|
| 101 |
- name: "{{'Configure' if (eseries_remove_all_configuration_state | default('present')) == 'present' else 'Unconfigure' }} inventory-defined hostgroup definitions" |
| 102 |
na_santricity_hostgroup: |
| 103 |
ssid: "{{ current_eseries_ssid }}" |
| 104 |
api_url: "{{ current_eseries_api_url }}" |
| 105 |
api_username: "{{ current_eseries_api_username }}" |
| 106 |
api_password: "{{ current_eseries_api_password }}" |
| 107 |
validate_certs: "{{ current_eseries_validate_certs | default(omit) }}" |
| 108 |
state: absent |
| 109 |
name: "{{ item }}" |
| 110 |
hosts: "{{ current_storage_array_hostgroups[item] | default(omit) }}" |
| 111 |
connection: local |
| 112 |
loop: "{{ lookup('list', unused_hostgroups) }}" |
| 113 |
when: "eseries_host_object is defined and (unused_hostgroups|length>0) and eseries_host_remove_unused_hostgroup is |
| 114 |
defined and eseries_host_remove_unused_hostgroup" |