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: <omitted> stdout: ' -12268.06'
stdout_lines: <omitted>
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
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/e4eb868d-54da-4c86-92c8-352f6c023086n%40googlegroups.com.