I have this output:
(1, ‘\r\n{“msg”: “service[component] - https://myip/myrest/v1/ fails to due to error 501 - None”, “failed”: true, “invocation”: {“module_args”: {“url_password”: null, “tasks”: [{“name”: null, “hostname”: “myapp”, “timeout”: “60”, “my_post_action”: “component”, “operation”: "shut, “instance”: “abc”}], “force”: false, “homedir”: null, “service”: null, “url”: null, “force_basic_auth”: false, “http_agent”: “ansible-httpget”, “cluster”: “homedir”, “state”: “present”, “BaseUrl”: “https://myapp/myrest/api/v1”, “url_username”: null, “client_key”: null, “validate_certs”: false, “client_cert”: null, “use_proxy”: true}}}\r\n’, ‘Shared connection to myapp closed.\r\n’)
But when i put condition on a registered variable
when : result is not failed ,
it says :
The ‘failed’ test expects a dictionary\n Error how can i put this condition then ?
Hi Ansible Gurus,
I have this output:
<myapp> (1, '\r\n{"msg": "service[component] - https://myip/myrest/v1/ fails to due to error 501 - None", "failed":
true, "invocation": {"module_args": {"url_password": null, "tasks": [{"name": null, "hostname": "myapp", "timeout":
"60", "my_post_action": "component", "operation": "shut, "instance": "abc"}], "force": false, "homedir": null,
"service": null, "url": null, "force_basic_auth": false, "http_agent": "ansible-httpget", "cluster": "homedir", "state":
"present", "BaseUrl": "https://myapp/myrest/api/v1", "url_username": null, "client_key": null, "validate_certs": false,
"client_cert": null, "use_proxy": true}}}\r\n', 'Shared connection to myapp closed.\r\n')
But when i put condition on a registered variable
when : result is not failed ,
it says :
The 'failed' test expects a dictionary\n Error how can i put this condition then ?
Rahul
Please share the relevant details about your playbook / task / inventory.
Here it is :
- name: my service shut
my_service:
baseUrl: "{{ base_rest_url }}"
tasks:
- action: service_shut
operation: shut
hostname: "{{ ansible_fqdn }}"
instance: "{{ item.instance }}"
state: present
register: result
with_items: "{{ my_instances_config }}"
when: result is not failed
here my_service is custom python module !
Hello Rahul,
the condition is check for each item in "my_instances_config" *before* running the task.
So it doesn't make sense to use "result" there as it is registered *after* running the task.
my idea is: i don’t want to stop the execution if this rest call is failed ! what i want that if this task failed , it should be skipped rather than failing entire execution !
Notice i dont want to use ignore_error kind of then , i want something conditional !
my idea is: i don't want to stop the execution if this rest call is failed ! what i want that if this task failed , it
should be skipped rather than failing entire execution !
Notice i dont want to use ignore_error kind of then , i want something conditional !
Hello Rahul,
you can override the failed state with failed_when instead of when, e.g.
failed_when: false
However that doesn't make sense. You should fix the problem in your API / in calling your API.
suppose i have a statement like :
until: result.failed == False and result is succeeded and result.content.allstarted in a task !
But i get error saying dict has no attribute allstarted ! Actually that is true also because this attribute comes only when result.failed == false ! But here until is trying to evaluate all 3 conditions together ! Is there any ways in which we can say that evaluate result.content.allstarted only when result.failed== false in until clause !