Hi,
I have a playbook with a task that greps for a string in a file. If the string is found the block should fail which is the case. However, in the fail module it fails to print the message.
Here is my playbook:
Here is my playbook:
`
Hi,
I have a playbook with a task that greps for a string in a file. If the string is found the block should fail which is the case. However, in the fail module it fails to print the message.
Here is my playbook:
Here is my playbook:
`
Hi,
I have a playbook with a task that greps for a string in a file. If the
string is found the block should fail which is the case. However, in
the fail module it fails to print the message.Here is my playbook:
Here is my playbook:
`
---
- name: "Play 1"
hosts: localhost
tasks:
- block:
- name: "Search for IP"
command: "grep -w {{ source_host }} {{ playbook_dir }}/allhost.hosts"
register: command_result
failed_when: command_result.rc == 0 and action == "onboard"rescue:
- name: Print custom conditional debug message
fail:
msg: >-
{{
command_result.rc == 0 |
You're missing parenthesis around the condition.
V/r,
James Cassell
Missing parentheses where?
My code is very similar to a working sample here:
fail:
msg: >-
{{
command_result.stdout is search(‘775’) |
ternary(
"This REQ is already Deployed. ,
“Database is not reachable.”
)
}}
Missing parentheses where?
Right above the answer
Close the comparison into the parenthesis
(command_result.rc == 0) |
The filter "|" has higher precedence compared to the comparison "==". Without
the parenthesis the filter is evaluated first and ternary returns "The
Database is not reachable.". This string is compared to command_result.rc and
the result is "msg": "False"
HTH,
-vlado