ansible-collections / ibm.spectrum_virtualize

IBM Spectrum Virtualize
GNU General Public License v3.0
21 stars 26 forks source link

Support host clusters in ibm_svc_vol_map module #10

Closed talorh closed 3 years ago

talorh commented 4 years ago
SUMMARY

Add the ability to map volumes to a host cluster when using ibm_svc_vol_map.

ISSUE TYPE
COMPONENT NAME

ibm_svc_vol_map module.

ADDITIONAL INFORMATION

This module when mapping a volume to multiple hosts, will map the volume to host #1 and consider that the volume is now mapped and ignore all subsequent hosts. While fixing this would be good, what would be better would be the ability to map to a host cluster. Use case is an automated DR test for VMware. Workaround is to use the Storwize REST API with ansible uri module.

This would be ideal:

- name: "Map my volumes to a host cluster"
  ibm.spectrum_virtualize.ibm_svc_vol_map:
    clustername: "my_cluster"
    username: "talor"
    password: "..."
    volname: "{{ item }}"
    hostcluster: "my-awesome-host-cluster"
    state: present
  loop:
    - "{{ import_storwize_volumes }}"

This is what I'm doing now, and it only ever maps the volume to the first host it iterates over.

- name: "Map my volumes to multiple hosts"
  ibm.spectrum_virtualize.ibm_svc_vol_map:
    clustername: "my_cluster"
    username: "talor"
    password: "..."
    volname: "{{ item[0] }}"
    host: "{{ item[1] }}"
    state: present
  with_nested:
    - "{{ import_storwize_volumes }}"
    - "{{ esx_hosts }}"

The workaround to get it mapped to remaining hosts is below (I'd loop over this playbook) per host per volume, and want to avoid having to do this. The variables "volume" and "host" are passed to this.

- debug:
    msg: "Processing {{ volume }}"

- name: "Give me yo storwize api token"
  uri:
    url: "https://my_cluster:7443/rest/auth"
    method: POST
    validate_certs: yes
    headers:
      X-Auth-Username: "talor"
      X-Auth-Password: "..."
  register: storwize_token
  no_log: true

- name: "Check yo host mapping"
  uri:
    url: "https://my_cluster:7443/rest/lsvdiskhostmap/{{ volume }}"
    method: POST
    headers:
      Content-Type: "application/json"
      X-Auth-Token: "{{ storwize_token.json.token }}"
    body_format: json
    validate_certs: yes
  register: mapping_state

- name: "Create an array of mapped hosts"
  set_fact:
    mapped_hosts: "{{ mapped_hosts | default([]) + [line_item.host_name] }}"
  with_items:
    - "{{ mapping_state.json }}"
  loop_control:
    loop_var: line_item

- name: "Create a glorious host mapping"
  uri:
    url: "https://my_cluster:7443/rest/mkvdiskhostmap/{{ volume }}"
    method: POST
    headers:
      Content-Type: "application/json"
      X-Auth-Token: "{{ storwize_token.json.token }}"
    body: '{"force": true, "host": "{{ host }}"}'
    body_format: json
    validate_certs: yes
  when: host not in mapped_hosts
Shilpi-J commented 4 years ago

Currently, we do not support host cluster in ibm_svc_vol_map module. It shall be supported in future releases. Thanks

Shilpi-J commented 3 years ago

Host cluster support added in 1.5.0