#Delete ontap images with rest_cli

1 messages · Page 1 of 1 (latest)

main cedar
#

Hi guys,
I'm writing a plybook to delete all no longer needed ontap images on the clusters.
I'm using the rest cli to delete the images. The playbooks fails with API not found.

- name: Get_fqdn_of_cluster_{{ outer_item }} 
  ansible.builtin.set_fact:
    netapp_cluster: "{{ lookup('dig', outer_item, 'flat=0') | json_query('owner') | regex_replace('\\.$', '') }}"

- name: Get_all_images
  netapp.ontap.na_ontap_rest_info:
    https: true
    validate_certs: false
    gather_subset:
      - cluster/software/packages
    fields:
      - 'version'
    use_python_keys: true
    hostname: "{{ netapp_cluster }}"
    username: "{{ netapp_username }}"
    password: "{{ netapp_password }}"
  register: netapp

- name: Delete_not_needed_images
  netapp.ontap.na_ontap_rest_cli:
    command: "cluster/software/packages/{{ item.version }}"
    verb: 'DELETE'
    hostname: "{{ netapp_cluster }}"
    username: "{{ netapp_username }}"
    password: "{{ netapp_password }}"
    https: true
    validate_certs: false
  with_items: "{{ netapp.ontap_info.cluster_software_packages.records }}"
  when:
    - item.version != '9.12.1P5'
    - item.version != '9.11.1P11'
#
failed: [localhost] (item={'version': '9.9.1P6', '_links': {'self': {'href': '/api/cluster/software/packages/9.9.1P6'}}}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "body": null,
            "cert_filepath": null,
            "command": "cluster/software/packages/9.9.1P6",
            "feature_flags": null,
            "force_ontap_version": null,
            "hostname": "<fqdn>",
            "http_port": null,
            "https": true,
            "key_filepath": null,
            "ontapi": null,
            "params": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "use_rest": "auto",
            "username": "netapp-ansible",
            "validate_certs": false,
            "verb": "DELETE"
        }
    },
    "item": {
        "_links": {
            "self": {
                "href": "/api/cluster/software/packages/9.9.1P6"
            }
        },
        "version": "9.9.1P6"
    },
    "msg": "Error: {'message': 'API not found', 'code': '3'}"
}

From the Ontap API documentation it should work in this way or did I miss something?

untold crane
#

You use the wrong module. na_ontap_rest_cli uses the api/private/cli/ API endpoint to allow ssh-like commands that have no real API equivalent. You have to use na_ontap_restit instead.