I am new to ansible tasks, am creating a yml which performs a login operation and if login gets failed, some script need to be called.
- name: Logging Action
shell: "/usr/local/bin/cqlsh -u xyzyx -p 1234abc"
register: loginoutput
ignore_errors: yes
no_log: True
- name: Run the cql script to create new user
shell: sh create-new-user.cql"
when: loginoutput|failed
for the above one i created taks that works fine.
My question, when performing login operation - it got failed and showing error messages like below...
I dont want to display the log messgaes even not any failed string in logs.
I tried no_log: True
, this gives
failed: [127.0.0.1] => {"censored": "results hidden due to no_log parameter", "changed": true, "rc": 1}
I don't want to show failed string in o/p.
You can't. no_log: True
is the best there is to prevent output.
If it helps, beside ignore_errors: yes
, there is the failed_when
option where you can define exactly what makes the task fail. The idea would be to not let the task fail in the first place.
- name: Logging Action
shell: "/usr/local/bin/cqlsh -u xyzyx -p 1234abc"
register: loginoutput
failed_when: false
no_log: True
So in this case, the task will never fail (false
) but you can provide any sophisticated condition which may be based on the output of the task.
Now, the task did not fail, but the return code of cqlsh
still is 1
, which you can use in the condition of the next task.
- name: Run the cql script to create new user
shell: sh create-new-user.cql"
when: loginoutput.rc == 1
In theory this should have the same outcome as before, just that the first task is not marked as failed and therefore no_log: True
should have the desired effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With