Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to hide failed log in ansible task

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.

like image 822
user3319565 Avatar asked Mar 01 '16 13:03

user3319565


1 Answers

You can't. no_log: Trueis 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.

like image 182
udondan Avatar answered Nov 05 '22 20:11

udondan