#"when" statements using na_ontap_rest_info output

1 messages · Page 1 of 1 (latest)

hollow root
#

I am revisiting code I made 4 years ago for some Day0 ONTAP Builds. I used the na_ontap_info regularly, and am converting to use the na_ontap_rest_info module. I'm having some trouble with using the registered output of it. I assume it's likely just syntax, but I find these kind of issues difficult to search forums/Google for, so am hoping someone here can help.

Here is the task to get the info, this works fine (in this example I just want the failover policy name and the service_policy).

- name: Get Node Management LIFs netapp.ontap.na_ontap_rest_info: <<: *clusterlogin gather_subset: - ip_interfaces_info fields: - 'name' - 'location.failover' - 'service_policy.name' use_python_keys: true register: node_mgmt_lifs tags: node_mgmt_lifs

Here is a snippet of the na_ontap_rest_info output:

"ontap_info": { "network_ip_interfaces": { "num_records": 6, "records": [ { "location": { "failover": "broadcast_domain_only" }, "name": "cluster_mgmt", "service_policy": { "name": "default-management" }, "uuid": "106c4ac0-10d4-11ef-9d9c-005056a095dd" }, { "location": { "failover": "home_node_only" }, "name": "CJCLUSTER-01_mgmt1", "service_policy": { "name": "default-management" }, "uuid": "892e5d80-10cf-11ef-9d9c-005056a095dd" },

Had to split over two messages to get under the 2000 character limit.

#

I want to use this in another task, in this example, to delete the LIF when the failover location is "home_node_only" and the service_policy name is "default-management". Here is my task:

- name: Remove Auto-Generated Node Management LIFs netapp.ontap.na_ontap_interface: <<: *clusterlogin state: absent vserver: "{{ inventory_hostname }}" interface_name: "{{ item.name }}" with_items: "{{ node_mgmt_lifs.ontap_info.network_ip_interfaces.records }}" when: - node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['failover']['location'] == 'home_node_only' - node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['service_policy']['name'] == 'default-management' tags: node_mgmt_lifs

When clauses like this used to work with the na_ontap_info module output, but I'm having trouble getting it to work with the rest module. The error I get for this is:

fatal: [CJCLUSTER]: FAILED! => { "msg": "The conditional check 'node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['failover']['location'] == 'home_node_only'' failed. The error was: error while evaluating conditional (node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['failover']['location'] == 'home_node_only'): list object has no element {'uuid': '106c4ac0-10d4-11ef-9d9c-005056a095dd', 'name': 'cluster_mgmt', 'location': {'failover': 'broadcast_domain_only'}, 'service_policy': {'name': 'default-management'}}\n\nThe error appears to be in '<somepath>/main.yml': line 83, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Remove Auto-Generated Node Management LIFs\n ^ here\n" }

The error shows all the elements for the first LIF, so it seems to be reaching the first records, but then fails.

Has anyone got an tips on how to achieve this?

Thanks!

tall apex
#

You got the structure for failover mixed up in your condition.
Output was "location": { "failover": "broadcast_domain_only" },

So the condition should be ['location']['failover'] == 'home_node_only'

hollow root
#

Thanks @tall apex , I didnt even realise. but with the correct order, same issue.

when: - node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['location']['failover'] == 'home_node_only' - node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['service_policy']['name'] == 'default-management'

Results in the same sort of error:

fatal: [CJCLUSTER]: FAILED! => { "msg": "The conditional check 'node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['location']['failover'] == 'home_node_only'' failed. The error was: error while evaluating conditional (node_mgmt_lifs.ontap_info.network_ip_interfaces.records[item]['location']['failover'] == 'home_node_only'): list object has no element {'uuid': '106c4ac0-10d4-11ef-9d9c-005056a095dd', 'name': 'cluster_mgmt', 'location': {'failover': 'broadcast_domain_only'}, 'service_policy': {'name': 'default-management'}}\n\nThe error appears to be in '<somepath>/main.yml': line 83, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Remove Auto-Generated Node Management LIFs\n ^ here\n" }

I am finding the syntax for this difficult.

tall apex
#

Variable handling is awful in Ansible 😦

#

I tested this successfully:

`loop: "{{ node_mgmt_lifs.ontap_info.network_ip_interfaces.records }}"
when:

  • item.location.failover == 'home_node_only'`
hollow root
#

@tall apex you sir, are a legend! That works. So simple. Thank you!!!!