i’m running an API call in order to get indexes in Elastic – The output is saved inside a registry (index_list).
I want to run an additional job that runs only in case the policy name can be found in the register output – The solution I gave is not working (I’m guessing that I need to loop inside the registry on specific fields ) -
in the example below i have a policy ID named what
API Call
- name: Get ISM_retention policy
uri:
url: http://elastic:9200/_opendistro/_ism/policies
method: GET
timeout: 180
body_format: json
register: index_list
The debug condition that I’m trying to run – In the register output you can find the u’policy_id’: u’what’
- debug: msg: hello
when: “‘what’ in index_list”
The register output
MSG: (I have marked the policy ID in bold)
{u’status’: 200, u’content_length’: u’1919’, u’cookies’: {}, u’url’: u’http://elastic:9200/_opendistro/_ism/policies’, u’changed’: False, u’elapsed’: 0, u’failed’: False, u’json’: {u’total_policies’: 3, u’policies’: [{u’policy’: {u’default_state’: u’hot’, u’description’: u’policy for delete index’, u’last_updated_time’: 1667984798760, u’error_notification’: None, u’states’: [{u’transitions’: [{u’conditions’: {u’min_index_age’: u’1d’}, u’state_name’: u’delete’}], u’name’: u’hot’, u’actions’: [{u’retry’: {u’count’: 3, u’delay’: u’1m’, u’backoff’: u’exponential’}, u’open’: {}}]}, {u’transitions’: , u’name’: u’delete’, u’actions’: [{u’retry’: {u’count’: 3, u’delay’: u’1m’, u’backoff’: u’exponential’}, u’delete’: {}}]}], u’ism_template’: [{u’index_patterns’: [u’audit-‘], u’priority’: 100, u’last_updated_time’: 1667984798760}], u’schema_version’: 15, u’policy_id’: u’policy_1’}, u’_id’: u’policy_1’, u’_seq_no’: 104149, u’_primary_term’: 1}, {u’policy’: {u’default_state’: u’hot’, u’description’: u’kuku index retenation flow’, u’last_updated_time’: 1668061803458, u’error_notification’: None, u’states’: [{u’transitions’: [{u’conditions’: {u’min_index_age’: u’1d’}, u’state_name’: u’delete’}], u’name’: u’hot’, u’actions’: [{u’retry’: {u’count’: 3, u’delay’: u’1m’, u’backoff’: u’exponential’}, u’open’: {}}]}, {u’transitions’: [], u’name’: u’delete’, u’actions’: [{u’retry’: {u’count’: 3, u’delay’: u’1m’, u’backoff’: u’exponential’}, u’delete’: {}}]}], u’ism_template’: [{u’index_patterns’: [u’kuku-‘], u’priority’: 100, u’last_updated_time’: 1668061803458}], u’schema_version’: 15, u’policy_id’: u’policy_kuku’}, u’_id’: u’policy_kuku’, u’_seq_no’: 143284, u’_primary_term’: 1}, {u’policy’: {u’default_state’: u’hot’, u’description’: u’what index retenation flow’, u’last_updated_time’: 1668074528411, u’error_notification’: None, u’states’: [{u’transitions’: [{u’conditions’: {u’min_index_age’: u’1d’}, u’state_name’: u’delete’}], u’name’: u’hot’, u’actions’: [{u’retry’: {u’count’: 3, u’delay’: u’1m’, u’backoff’: u’exponential’}, u’open’: {}}]}, {u’transitions’: , u’name’: u’delete’, u’actions’: [{u’retry’: {u’count’: 3, u’delay’: u’1m’, u’backoff’: u’exponential’}, u’delete’: {}}]}], u’ism_template’: [{u’index_patterns’: [u’what-*‘], u’priority’: 100, u’last_updated_time’: 1668074528411}], u’schema_version’: 15, u’policy_id’: u’what’}, u’_id’: u’what’, u’_seq_no’: 150078, u’_primary_term’: 1}]}, u’content_type’: u’application/json; charset=UTF-8’, u’msg’: u’OK (1919 bytes)‘, u’redirected’: False, u’cookies_string’: u’'}