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):
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.
I also tried a less than zero condition, but ignores it.
I think there are two problems:
Here is the error
Here is the value of the .stdout for the condition check:
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
$ cat symianarmy01.yml
---
# symianarmy01.yml
- name: Reading number from a file
hosts: localhost
gather_facts: false
vars:
fname: /tmp/impact.txt
content: ' -12268.06'
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e4eb868d-54da-4c86-92c8-352f6c023086n%40googlegroups.com.
-- Todd