# Help Using an .stdout as a VAR Used in a WHEN Condition

**URL:** <https://forum.ansible.com/t/help-using-an-stdout-as-a-var-used-in-a-when-condition/38637>\
**Category:** Ansible Project\
**Created:** [December 26, 2023, 10:46pm UTC](https://forum.ansible.com/t/help-using-an-stdout-as-a-var-used-in-a-when-condition/38637 "2023-12-26T22:46:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Symian](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/symian/32/8301_2.png) [@Symian](https://forum.ansible.com/u/Symian)\
**Post date:** [December 26, 2023, 10:46pm UTC](https://forum.ansible.com/t/help-using-an-stdout-as-a-var-used-in-a-when-condition/38637/1 "2023-12-26T22:46:54Z")

</div>

Hello. New to this wonderful Ansible thing. I am a database guy. I have an Oracle process that spits out a file that looks like this (but the value could be different at each run):

[oracle@lnx0016 scripts]$ more /tmp/impact.txt -12268.06

Then, within the same playbook, Ansible playbook parses it, and if the value is a negative (less than 0), it is supposed to kick off a whole another block.

- name: opatch\_direct | Export the Post-change Impact Score for for {{ db\_name }} shell: ‘cat /tmp/impact.txt’ register: impact\_score\_literal - name: opatch\_direct | GO / NOGO decision for {{ oracle\_home }} and {{ db\_name }} block: … when: “‘-’ not in impact\_score\_literal.stdout”

I also tried a less than zero condition, but ignores it.  
I think there are two problems:

1. The number " -12268.06" has a heading empty space
2. The data type may be wrong? May be I should use something other than “cat”?

Here is the error

TASK [opatch\_direct | Stop database ORCLCDB before rolling back 35740258 for /opt/oracle/product/21c/dbhome\_1] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* task path: /home/oracle/ansible/playbooks/opatch\_direct.yml:185 fatal: [lnx006]: FAILED! =\> msg: |- The conditional check ‘’-’ not in impact\_score\_literal.stdout’ failed. The error was: error while evaluating conditional (‘-’ not in impact\_score\_literal.stdout): ‘dict object’ has no attribute ‘stdout’ The error appears to be in ‘/home/oracle/ansible/playbooks/opatch\_direct.yml’: line 185, column 11, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: - name: opatch\_direct | Stop database {{db\_name}} before rolling back {{ patch\_id }} for {{ oracle\_home }} ^ here We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance: with\_items: - {{ foo }} Should be written as: with\_items: - “{{ foo }}” PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* lnx006 : ok=17 changed=12 unreachable=0 failed=1 skipped=1 rescued=0 ignored=0

Here is the value of the .stdout for the condition check:

changed: [lnx006] =\> changed=true cmd: cat /tmp/impact.txt delta: ‘0:00:00.004104’ end: ‘2023-12-26 15:38:15.595984’ invocation: module\_args: \_raw\_params: cat /tmp/impact.txt \_uses\_shell: true argv: null chdir: null creates: null executable: null removes: null stdin: null stdin\_add\_newline: true strip\_empty\_ends: true warn: true rc: 0 start: ‘2023-12-26 15:38:15.591880’ stderr: ‘’ stderr\_lines: stdout: ’ -12268.06’ stdout\_lines:

What I find interesting is that the condition works ONLY with an == sign, not \<\>. That value , if it matches the /tmp/impact.txt contents, works, meaning Ansible keeps rolling, follows the condition as it should. But that is not what I need. I need it to kick off the block only if the number is negative.

Please help  
Thanks  
Symian

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [January 10, 2024, 3:04am UTC](https://forum.ansible.com/t/help-using-an-stdout-as-a-var-used-in-a-when-condition/38637/2 "2024-01-10T03:04:52Z")

</div>

```auto
**$ cat symianarmy01.yml**
---
# symianarmy01.yml
- name: Reading number from a file
  hosts: localhost
  gather_facts: false
  vars:
    <b>fname: /tmp/impact.txt
    content: ' -12268.06'</b>
  tasks:
    - name: Create our temporary file
      ansible.builtin.copy:
        content: '{{ content }}'
        dest: '{{ fname }}'

    - name: Read integer from /tmp/impact.txt
      ansible.builtin.shell: |
        **read impact < "{{ fname }}"**
        **echo "$impact"**
      args:
        executable: /bin/bash
      register: **impact**

    - name: **Is impact less than zero**
      ansible.builtin.debug:
        msg: 'Test: **{{ impact.stdout_lines | first | float < 0 }}**'

**$ ansible-playbook -v symianarmy01.yml**
Using /etc/ansible/ansible.cfg as config file

PLAY [Reading number from a file] ***************************

TASK [Create our temporary file] *****************************
ok: [localhost] => changed=false 
  checksum: c5aea891bcfc6021ef0c26a053039b72aef67c30
  dest: /tmp/impact.txt
  gid: 12428
  group: utoddl
  mode: '0664'
  owner: utoddl
  path: /tmp/impact.txt
  secontext: unconfined_u:object_r:user_tmp_t:s0
  size: 11
  state: file
  uid: 12428

TASK [Read integer from /tmp/impact.txt] *********************
changed: [localhost] => changed=true 
  cmd: |-
    read impact < "/tmp/impact.txt"
    echo "$impact"
  delta: '0:00:00.002843'
  end: '2024-01-09 21:59:56.534851'
  msg: ''
  rc: 0
  start: '2024-01-09 21:59:56.532008'
  stderr: ''
  stderr_lines: <omitted>
  stdout: '-12268.06'
  stdout_lines: <omitted>

TASK [**Is impact less than zero**] *****************************
ok: [localhost] => 
  msg: 'Test: **True**'

PLAY RECAP **************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   

```
