7

I am writing a simple Ansible playbook to run RHEL leap second detector on Linux boxes with mixed distribution.

here is the playbook

---
- hosts: Linux
  vars_files:
    - ../group_vars/Linux.yml

  tasks:

    - name: Running RHEL leap second detector (will skip if distirubtion is not RHEL)
      when: ansible_distribution == "RedHat"
      script: ../scripts/leap_vulnerability.sh
      register: result
      changed_when: false

    - name: RHEL Lead second detector result
      when: ansible_distribution == "RedHat"
      fail: msg="Kernel {{ansible_kernel}} is vulnerable"
      failed_when: "'kernel is vulnerable' in result.stdout"

it is working fine and here is an example of output

TASK: [Running RHEL leap second detector (will skip if distirubtion is not RHEL)] ***
skipping: [UTIL02]
skipping: [UTIL01]
ok: [SERV01]
ok: [SERV02]

TASK: [RHEL Lead second detector result] **************************************
skipping: [UTIL02]
skipping: [UTIL01]
failed: [SERV01] => {"failed": true, "failed_when_result": true}
msg: Kernel 2.6.18-53.el5 is vulnerable
failed: [SERV02] => {"failed": true, "failed_when_result": true}
msg: Kernel 2.6.18-53.el5 is vulnerable

PLAY RECAP ********************************************************************

UTIL01            : ok=1    changed=0    unreachable=0    failed=0
UTIL02            : ok=1    changed=0    unreachable=0    failed=0
SERV01            : ok=2    changed=0    unreachable=0    failed=1
SERV02            : ok=2    changed=0    unreachable=0    failed=1

As you can see, there is an extra line of message I don't really want.

failed: [SERV01] => {"failed": true, "failed_when_result": true}

Is it possible not to print that condition evaluation message just print the error message I defined ? something like following

failed: Kernel 2.6.18-53.el5 is vulnerable

2 Answers2

1

There seems no way to change the normal output from ansible-playbook. But you can generate additional output by using callback plugins.

You might be able to write a plugin to get your own output, while the normal output totally suppressed by redirecting it to /dev/null.

yaegashi
  • 12,326
  • It would be nice if we can write some simply python code in Ansible playbook, like PHP or ERB files. That would be awesome. – Ask and Learn Jun 10 '15 at 10:46
1

This might be a little late, but you don't need to use failed_when when you are using the fail module. A regular when should be enough and won't display the condition evaluation message.