ansible-collections / netapp.ontap

Ansible collection to support NetApp ONTAP configuration.
https://galaxy.ansible.com/netapp/ontap
GNU General Public License v3.0
56 stars 36 forks source link

Deleting a subsystem fails if vserver doesn't exist #16

Closed ChrisSchmittAtNetapp closed 2 years ago

ChrisSchmittAtNetapp commented 3 years ago

Summary

When you try to delete a vserver the task will fail if the vserver you're trying to delete on doesn't exist. In this scenario the task should pass because if the vserver doesn't exist then the subsystem definitely doesn't exist.

Component Name

netapp.ontap.na_ontap_nvme_subsystem

Ansible Version

(base) [root@frontier-jlcarter epic]# ansible --version
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller
starting with Ansible 2.12. Current version: 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0]. This feature will be removed from ansible-core in version 2.12.
Deprecation warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.
ansible [core 2.11.2]
  config file = /root/cschmitt/git/epic/ansible.cfg
  configured module search path = ['/root/cschmitt/git/epic/ansible-library']
  ansible python module location = /root/anaconda3/lib/python3.7/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /root/anaconda3/bin/ansible
  python version = 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0]
  jinja version = 2.10.3
  libyaml = True

ONTAP Collection Version

$ ansible-galaxy collection list
# /usr/share/ansible/collections/ansible_collections
Collection   Version
------------ -------
netapp.ontap 21.7.0

# /root/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
ansible.windows   1.5.0
brocade.fos       1.2.0
community.general 2.0.0
community.vmware  1.9.0
community.windows 1.3.0
netapp.ontap      20.11.0

# /root/anaconda3/lib/python3.7/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.0
ansible.netcommon             2.2.0
ansible.posix                 1.2.0
ansible.utils                 2.3.0
ansible.windows               1.7.0
arista.eos                    2.2.0
awx.awx                       19.2.2
azure.azcollection            1.7.0
check_point.mgmt              2.0.0
chocolatey.chocolatey         1.1.0
cisco.aci                     2.0.0
cisco.asa                     2.0.2
cisco.intersight              1.0.15
cisco.ios                     2.3.0
cisco.iosxr                   2.3.0
cisco.meraki                  2.4.2
cisco.mso                     1.2.0
cisco.nso                     1.0.3
cisco.nxos                    2.4.0
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.2.0
community.aws                 1.5.0
community.azure               1.0.0
community.crypto              1.7.1
community.digitalocean        1.7.0
community.docker              1.8.0
community.fortios             1.0.0
community.general             3.3.0
community.google              1.0.0
community.grafana             1.2.1
community.hashi_vault         1.3.0
community.hrobot              1.1.1
community.kubernetes          1.2.1
community.kubevirt            1.0.0
community.libvirt             1.0.1
community.mongodb             1.2.1
community.mysql               2.1.0
community.network             3.0.0
community.okd                 1.1.2
community.postgresql          1.3.0
community.proxysql            1.0.0
community.rabbitmq            1.0.3
community.routeros            1.2.0
community.skydive             1.0.0
community.sops                1.1.0
community.vmware              1.11.0
community.windows             1.5.0
community.zabbix              1.3.0
containers.podman             1.6.1
cyberark.conjur               1.1.0
cyberark.pas                  1.0.7
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            3.5.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.10.1
fortinet.fortimanager         2.1.2
fortinet.fortios              2.1.1
frr.frr                       1.0.3
gluster.gluster               1.0.1
google.cloud                  1.0.2
hetzner.hcloud                1.4.3
hpe.nimble                    1.1.3
ibm.qradar                    1.0.3
infinidat.infinibox           1.2.4
inspur.sm                     1.2.0
junipernetworks.junos         2.3.0
kubernetes.core               1.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.2.0
netapp.azure                  21.7.0
netapp.cloudmanager           21.7.0
netapp.elementsw              21.6.1
netapp.ontap                  21.7.0
netapp.um_info                21.6.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.1.1
ngine_io.cloudstack           2.1.0
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.5.0
openvswitch.openvswitch       2.0.0
ovirt.ovirt                   1.5.3
purestorage.flasharray        1.8.0
purestorage.flashblade        1.6.0
sensu.sensu_go                1.11.1
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.18.0
theforeman.foreman            2.1.1
vyos.vyos                     2.3.1
wti.remote                    1.0.1

ONTAP Version

NetApp Release 9.8P1

Playbook

- name: Delete subsystem
  netapp.ontap.na_ontap_nvme_subsystem:
    state: absent
    subsystem: "{{ item.name }}"
    vserver: "{{ item.vserver }}"
    hostname: "{{ item.ntap_hostname }}"
    username: "{{ item.ntap_username }}"
    password: "{{ item.ntap_password }}"
    skip_host_check: yes
    skip_mapped_check: yes
  connection: local
  loop: "{{ subsystems }}"
  when: subsystems is defined

Steps to Reproduce

- name: Delete subsystem
  netapp.ontap.na_ontap_nvme_subsystem:
    state: absent
    subsystem: "{{ item.name }}"
    vserver: "{{ item.vserver }}"
    hostname: "{{ item.ntap_hostname }}"
    username: "{{ item.ntap_username }}"
    password: "{{ item.ntap_password }}"
    skip_host_check: yes
    skip_mapped_check: yes
  connection: local
  loop: "{{ subsystems }}"
  when: subsystems is defined

Expected Results

The delete subsystem task should pass since the subsystem does not exist, ensuring the subsystem already doesn't exist.

Actual Results

The task fails with the following error, the main error being "netapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15698:Specified vserver not found"

<10.63.158.231> EXEC /bin/sh -c 'echo ~root && sleep 0'
<10.63.158.231> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073 `" && echo ansible-tmp-1628784158.868534-6643-235397253737073="` echo /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073 `" ) && sleep 0'
Using module file /root/.ansible/collections/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py
<10.63.158.231> PUT /root/.ansible/tmp/ansible-local-6371d3ezszzr/tmphcoigcha TO /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py
<10.63.158.231> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/ /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py && sleep 0'
<10.63.158.231> EXEC /bin/sh -c '/root/anaconda3/bin/python3 /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py && sleep 0'
<10.63.158.231> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py", line 100, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py", line 92, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py", line 41, in invoke_module
    run_name='__main__', alter_sys=True)
  File "/root/anaconda3/lib/python3.7/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/root/anaconda3/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/root/anaconda3/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py", line 363, in <module>
  File "/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py", line 359, in main
  File "/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py", line 334, in apply
  File "/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/module_utils/netapp.py", line 294, in ems_log_event
  File "/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/module_utils/netapp.py", line 287, in ems_log_event
  File "/root/anaconda3/lib/python3.7/site-packages/netapp_lib/api/zapi/zapi.py", line 301, in invoke_successfully
    raise NaApiError(code, msg)
netapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15698:Specified vserver not found
failed: [10.63.158.231] (item={'name': 'epic_nva_2_subsystem_4', 'namespace_paths': ['/vol/epic_nva_2_vserver_4_db_1/epic_nva_2_vserver_4_namespace_1', '/vol/epic_nva_2_vserver_4_db_2/epic_nva_2_vserver_4_namespace_2', '/vol/epic_nva_2_vserver_4_db_3/epic_nva_2_vserver_4_namespace_3', '/vol/epic_nva_2_vserver_4_db_4/epic_nva_2_vserver_4_namespace_4', '/vol/epic_nva_2_vserver_4_db_5/epic_nva_2_vserver_4_namespace_5', '/vol/epic_nva_2_vserver_4_db_6/epic_nva_2_vserver_4_namespace_6', '/vol/epic_nva_2_vserver_4_db_7/epic_nva_2_vserver_4_namespace_7', '/vol/epic_nva_2_vserver_4_db_8/epic_nva_2_vserver_4_namespace_8'], 'ostype': 'vmware', 'vserver': 'epic_nva_2_vserver_4', 'ntap_hostname': '10.63.158.231', 'ntap_username': 'admin', 'ntap_password': 'Netapp123'}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": {
        "name": "epic_nva_2_subsystem_4",
        "namespace_paths": [
            "/vol/epic_nva_2_vserver_4_db_1/epic_nva_2_vserver_4_namespace_1",
            "/vol/epic_nva_2_vserver_4_db_2/epic_nva_2_vserver_4_namespace_2",
            "/vol/epic_nva_2_vserver_4_db_3/epic_nva_2_vserver_4_namespace_3",
            "/vol/epic_nva_2_vserver_4_db_4/epic_nva_2_vserver_4_namespace_4",
            "/vol/epic_nva_2_vserver_4_db_5/epic_nva_2_vserver_4_namespace_5",
            "/vol/epic_nva_2_vserver_4_db_6/epic_nva_2_vserver_4_namespace_6",
            "/vol/epic_nva_2_vserver_4_db_7/epic_nva_2_vserver_4_namespace_7",
            "/vol/epic_nva_2_vserver_4_db_8/epic_nva_2_vserver_4_namespace_8"
        ],
        "ntap_hostname": "10.63.158.231",
        "ntap_password": "Netapp123",
        "ntap_username": "admin",
        "ostype": "vmware",
        "vserver": "epic_nva_2_vserver_4"
    },
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py\", line 100, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py\", line 92, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1628784158.868534-6643-235397253737073/AnsiballZ_na_ontap_nvme_subsystem.py\", line 41, in invoke_module\n    run_name='__main__', alter_sys=True)\n  File \"/root/anaconda3/lib/python3.7/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/root/anaconda3/lib/python3.7/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/root/anaconda3/lib/python3.7/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py\", line 363, in <module>\n  File \"/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py\", line 359, in main\n  File \"/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/modules/na_ontap_nvme_subsystem.py\", line 334, in apply\n  File \"/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/module_utils/netapp.py\", line 294, in ems_log_event\n  File \"/tmp/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload_pzje7rjz/ansible_netapp.ontap.na_ontap_nvme_subsystem_payload.zip/ansible_collections/netapp/ontap/plugins/module_utils/netapp.py\", line 287, in ems_log_event\n  File \"/root/anaconda3/lib/python3.7/site-packages/netapp_lib/api/zapi/zapi.py\", line 301, in invoke_successfully\n    raise NaApiError(code, msg)\nnetapp_lib.api.zapi.zapi.NaApiError: NetApp API failed. Reason - 15698:Specified vserver not found\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
lonico commented 3 years ago

Makes sense.

I think it's the right thing to do, but it's a big change in behavior. And something we should also do for other modules. But yes, if you don't want a resource to be present, it should be OK if any of the supporting resources are missing.

carchi8py commented 2 years ago

We have an internal story DEVOPS-4857 open for this issue.

lonico commented 2 years ago

fixed in 21.22.0