Repository: ansible-collections/community.vmware

Issue:
Feature: community.vmware.vmware_cluster_ha missing options  
Hi

After pinging @Akasurde on slack , he's asked me to raise a fr.

So in HA I'm missing options for things like : -

Response for Host Isolation
Datastore with PDL
Datastore with APD

seems to be in the API https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.cluster.VmComponentProtectionSettings.html

also, i cant see options for advanced settings which we use a lot. https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.avail.doc/GUID-E0161CB5-BD3F-425F-A7E0-BF83B005FECA.html

dasconfig 

![image](https://user-images.githubusercontent.com/22365085/96597131-6074a500-12e5-11eb-877a-b69f818fe677.png)

![image](https://user-images.githubusercontent.com/22365085/96597362-a7fb3100-12e5-11eb-80cb-f9b8a719b5be.png)



Discussion:
What ansible version are we talking about?

> So in HA I'm missing options for things like : -
> 
> Response for Host Isolation

Actually, in 2.10 there is a [host_isolation_response](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_cluster_ha_module.html) option.

> Datastore with PDL
> Datastore with APD

Yes, I think these are really missing. I'd love to have a look at this but I don't have much time at the moment :-(

> also, i cant see options for advanced settings which we use a lot. https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.avail.doc/GUID-E0161CB5-BD3F-425F-A7E0-BF83B005FECA.html

In ansible 2.10, there should be also an `advanced_settings` option for this modules. I think there's no example for this but it should work similar to the one in [vmware_cluster_drs](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_cluster_drs_module.html#examples)

Hi -

so these three in particular I think. I think your correct "Response for Host Isolation" is there, confusion over this and "host failure response"

![image](https://user-images.githubusercontent.com/22365085/96618711-30390080-12fd-11eb-97eb-65dba12c27bf.png)

i'm on 2.9.13 so will upgrade to 2.10 and see if that helps ha advanced settings. 

There's also a [ha_vm_monitoring](https://docs.ansible.com/ansible/latest/collections/community/vmware/vmware_cluster_ha_module.html) option in 2.10, I think this deals with `VM Monitoring`.

So, actually, I think we're down to missing options for `Datastore with PDL` and `Datastore with APD`.

> i'm on 2.9.13 so will upgrade to 2.10 and see if that helps ha advanced settings.

Alternatively, you can try to stay on ansible 2.9.13 and install [the collection](https://galaxy.ansible.com/community/vmware). For me, at least at the moment, it's easier to use ansible 2.10 via pip instead of using the collection on top of ansible 2.9. That's not really a technical problem, more a compliance thing... but maybe it's the other way round for you.
so i'm using 2.9.13 with the collection on top. advanced settings are there, apologies it was staring me in the face.

so yes i think its just PDL/APD settings I'm missing

thanks

Could you please have a look at PR #477? This should implement the PDL/APD settings you're missing. 

Resolving patch:
diff --git a/plugins/modules/vmware_cluster_ha.py b/plugins/modules/vmware_cluster_ha.py
--- a/plugins/modules/vmware_cluster_ha.py
+++ b/plugins/modules/vmware_cluster_ha.py
@@ -173,6 +173,20 @@
       - A dictionary of advanced HA settings.
       default: {}
       type: dict
+    apd_response:
+      description:
+      - VM storage protection setting for storage failures categorized as All Paths Down (APD).
+      type: str
+      default: 'warning'
+      choices: [ 'disabled', 'warning', 'restartConservative', 'restartAggressive' ]
+      version_added: '1.4.0'
+    pdl_response:
+      description:
+      - VM storage protection setting for storage failures categorized as Permenant Device Loss (PDL).
+      type: str
+      default: 'warning'
+      choices: [ 'disabled', 'warning', 'restartAggressive' ]
+      version_added: '1.4.0'
 extends_documentation_fragment:
 - community.vmware.vmware.documentation
 
@@ -314,6 +328,10 @@ def check_ha_config_diff(self):
             != self.params.get("ha_vm_max_failures")
             or das_config.defaultVmSettings.vmToolsMonitoringSettings.maxFailureWindow
             != self.params.get("ha_vm_max_failure_window")
+            or das_config.defaultVmSettings.vmComponentProtectionSettings.vmStorageProtectionForAPD
+            != self.params.get("apd_response")
+            or das_config.defaultVmSettings.vmComponentProtectionSettings.vmStorageProtectionForPDL
+            != self.params.get("pdl_response")
         ):
             return True
 
@@ -373,6 +391,11 @@ def configure_ha(self):
                     das_vm_config.restartPriority = self.params.get('ha_restart_priority')
                     das_vm_config.isolationResponse = self.host_isolation_response
                     das_vm_config.vmToolsMonitoringSettings = vm_tool_spec
+
+                    das_vm_config.vmComponentProtectionSettings = vim.cluster.VmComponentProtectionSettings()
+                    das_vm_config.vmComponentProtectionSettings.vmStorageProtectionForAPD = self.params.get('apd_response')
+                    das_vm_config.vmComponentProtectionSettings.vmStorageProtectionForPDL = self.params.get('pdl_response')
+
                     cluster_config_spec.dasConfig.defaultVmSettings = das_vm_config
 
                 cluster_config_spec.dasConfig.admissionControlEnabled = self.ha_admission_control
@@ -461,6 +484,12 @@ def main():
         failover_host_admission_control=dict(type='dict', options=dict(
             failover_hosts=dict(type='list', elements='str', required=True),
         )),
+        apd_response=dict(type='str',
+                          choices=['disabled', 'warning', 'restartConservative', 'restartAggressive'],
+                          default='warning'),
+        pdl_response=dict(type='str',
+                          choices=['disabled', 'warning', 'restartAggressive'],
+                          default='warning'),
     ))
 
     module = AnsibleModule(


Test patch:
diff --git a/tests/integration/targets/vmware_cluster_ha/tasks/main.yml b/tests/integration/targets/vmware_cluster_ha/tasks/main.yml
--- a/tests/integration/targets/vmware_cluster_ha/tasks/main.yml
+++ b/tests/integration/targets/vmware_cluster_ha/tasks/main.yml
@@ -16,7 +16,6 @@
     cluster_name: test_cluster_ha
     state: present
 
-# Testcase 0001: Enable HA
 - name: Enable HA
   vmware_cluster_ha:
     validate_certs: false
@@ -26,109 +25,174 @@
     datacenter_name: "{{ dc1 }}"
     cluster_name: test_cluster_ha
     enable_ha: true
-  register: cluster_ha_result_0001
+  register: enable_ha_result
 
 - name: Ensure HA is enabled
   assert:
     that:
-        - "{{ cluster_ha_result_0001.changed == true }}"
+      - enable_ha_result.changed
 
-# Testcase 0002: Enable Slot based Admission Control
-- name: Enable Slot based Admission Control
-  vmware_cluster_ha:
-    validate_certs: false
-    hostname: "{{ vcenter_hostname }}"
-    username: "{{ vcenter_username }}"
-    password: "{{ vcenter_password }}"
-    datacenter_name: "{{ dc1 }}"
-    cluster_name: test_cluster_ha
-    enable_ha: true
-    slot_based_admission_control:
-      failover_level: 1
-  register: cluster_ha_result_0002
+- when: vcsim is not defined
+  block:
+  - name: Change APD response to "restartAggressive" (check-mode)
+    vmware_cluster_ha: &change_apd_response
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+      apd_response: 'restartAggressive'
+    check_mode: true
+    register: change_apd_response_check
 
-- name: Ensure Admission Cotrol is enabled
-  assert:
-    that:
-        - "{{ cluster_ha_result_0002.changed == true }}"
+  - assert:
+      that:
+        - change_apd_response_check.changed
 
-# Testcase 0003: Enable Cluster resource Percentage based Admission Control
-- name: Enable Cluster resource Percentage based Admission Control
-  vmware_cluster_ha:
-    validate_certs: false
-    hostname: "{{ vcenter_hostname }}"
-    username: "{{ vcenter_username }}"
-    password: "{{ vcenter_password }}"
-    datacenter_name: "{{ dc1 }}"
-    cluster_name: test_cluster_ha
-    enable_ha: true
-    reservation_based_admission_control:
-      auto_compute_percentages: false
-      failover_level: 1
-      cpu_failover_resources_percent: 33
-      memory_failover_resources_percent: 33
-  register: cluster_ha_result_0003
-
-- name: Ensure Admission Cotrol is enabled
-  assert:
-    that:
-        - "{{ cluster_ha_result_0003.changed == true }}"
+  - name: Change APD response to "restartAggressive"
+    vmware_cluster_ha: *change_apd_response
+    register: change_apd_response
 
-# Testcase 0004: Set Isolation Response to powerOff
-- name: Set Isolation Response to powerOff
-  vmware_cluster_ha:
-    validate_certs: false
-    hostname: "{{ vcenter_hostname }}"
-    username: "{{ vcenter_username }}"
-    password: "{{ vcenter_password }}"
-    datacenter_name: "{{ dc1 }}"
-    cluster_name: test_cluster_ha
-    enable_ha: true
-    host_isolation_response: 'powerOff'
-  register: cluster_ha_result_0004
+  - assert:
+      that:
+        - change_apd_response.changed
 
-- name: Ensure Isolation Response is enabled
-  assert:
-    that:
-        - "{{ cluster_ha_result_0004.changed == true }}"
+  - name: Change APD response to "restartAggressive" again
+    vmware_cluster_ha: *change_apd_response
+    register: change_apd_response_again
 
-# Testcase 0005: Set Isolation Response to shutdown
-- name: Set Isolation Response to shutdown
-  vmware_cluster_ha:
-    validate_certs: false
-    hostname: "{{ vcenter_hostname }}"
-    username: "{{ vcenter_username }}"
-    password: "{{ vcenter_password }}"
-    datacenter_name: "{{ dc1 }}"
-    cluster_name: test_cluster_ha
-    enable_ha: true
-    host_isolation_response: 'shutdown'
-  register: cluster_ha_result_0005
+  - assert:
+      that:
+        - not change_apd_response_again.changed
 
-- name: Ensure Isolation Response is enabled
-  assert:
-    that:
-        - "{{ cluster_ha_result_0005.changed == true }}"
+  - name: Change APD response back to default
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
 
-# Testcase 0006: Disable HA
-- name: Disable HA
-  vmware_cluster_ha:
-    validate_certs: false
-    hostname: "{{ vcenter_hostname }}"
-    username: "{{ vcenter_username }}"
-    password: "{{ vcenter_password }}"
-    datacenter_name: "{{ dc1 }}"
-    cluster_name: test_cluster_ha
-    enable_ha: false
-  register: cluster_ha_result_0006
+  - name: Change PDL response to "restartAggressive" (check-mode)
+    vmware_cluster_ha: &change_pdl_response
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+      pdl_response: 'restartAggressive'
+    check_mode: true
+    register: change_pdl_response_check
 
-- name: Ensure HA is disabled
-  assert:
-    that:
-        - "{{ cluster_ha_result_0006.changed == true }}"
+  - assert:
+      that:
+        - change_pdl_response_check.changed
+
+  - name: Change PDL response to "restartAggressive"
+    vmware_cluster_ha: *change_pdl_response
+    register: change_pdl_response
+
+  - assert:
+      that:
+        - change_pdl_response.changed
+
+  - name: Change PDL response to "restartAggressive" again
+    vmware_cluster_ha: *change_pdl_response
+    register: change_pdl_response_again
+
+  - assert:
+      that:
+        - not change_pdl_response_again.changed
+
+  - name: Change PDL response back to default
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+
+  - name: Enable Slot based Admission Control
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+      slot_based_admission_control:
+        failover_level: 1
+    register: enable_slot_based_admission_control_result
+
+  - name: Ensure Admission Cotrol is enabled
+    assert:
+      that:
+        - enable_slot_based_admission_control_result.changed
+
+  - name: Enable Cluster resource Percentage based Admission Control
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+      reservation_based_admission_control:
+        auto_compute_percentages: false
+        failover_level: 1
+        cpu_failover_resources_percent: 33
+        memory_failover_resources_percent: 33
+    register: enable_percentage_based_admission_control_result
+
+  - name: Ensure Admission Cotrol is enabled
+    assert:
+      that:
+        - enable_percentage_based_admission_control_result.changed
+
+  - name: Set Isolation Response to powerOff
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+      host_isolation_response: 'powerOff'
+    register: isolation_response_poweroff_result
+
+  - name: Ensure Isolation Response is enabled
+    assert:
+      that:
+        - isolation_response_poweroff_result.changed
+
+  - name: Set Isolation Response to shutdown
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: true
+      host_isolation_response: 'shutdown'
+    register: isolation_response_shutdown_result
+
+  - name: Ensure Isolation Response is enabled
+    assert:
+      that:
+        - isolation_response_shutdown_result.changed
 
-- when: vcsim is not defined
-  block:
   - name: Change advanced setting "number of heartbeat datastores" (check-mode)
     vmware_cluster_ha: &change_num_heartbeat_ds
       validate_certs: false
@@ -137,6 +201,7 @@
       password: "{{ vcenter_password }}"
       datacenter_name: "{{ dc1 }}"
       cluster_name: test_cluster_ha
+      enable_ha: true
       advanced_settings:
           'das.heartbeatDsPerHost': '4'
     check_mode: true
@@ -170,8 +235,9 @@
       password: "{{ vcenter_password }}"
       datacenter_name: "{{ dc1 }}"
       cluster_name: test_cluster_ha
+      enable_ha: true
       advanced_settings:
-          'das.includeFTcomplianceChecks': 'false'
+          'das.includeFTcomplianceChecks': 'False'
     check_mode: true
     register: change_includeFTcomplianceChecks_check
 
@@ -195,6 +261,22 @@
       that:
         - not change_includeFTcomplianceChecks_again.changed
 
+  - name: Disable HA
+    vmware_cluster_ha:
+      validate_certs: false
+      hostname: "{{ vcenter_hostname }}"
+      username: "{{ vcenter_username }}"
+      password: "{{ vcenter_password }}"
+      datacenter_name: "{{ dc1 }}"
+      cluster_name: test_cluster_ha
+      enable_ha: false
+    register: disable_ha_result
+
+  - name: Ensure HA is disabled
+    assert:
+      that:
+        - disable_ha_result.changed
+
   # Delete test cluster
   - name: Delete test cluster
     vmware_cluster: