'Checking the result returned by a command, along with exit-status
Sorry I'm a little new to Ansible and don't quite understand playbooks completely, and was wondering if someone would be able to help me identify and fix my issue. I want to run a command which checks if a service is enabled, and returns "true" in stdout, and this is what I have so far.
Side note (incase the command seems confusing): The first parameter is the location of a binary that I must use, followed by the parameters I must provide the binary to receive my result.
command:
/opt/tableau/tableau_server/packages/customer-bin.123/tsm configuration get -k service.jmx_enabled:
exit-status: 0
stdout:
- "True"
Unfortunately this test case seems to be failing and produces the result: "stdout: patterns not found: [true]" and I have no idea what I'm doing wrong. If someone could look this over for me that would be awesome! EDIT: The default_test.yml playbook is run by molecule when testing roles.
Solution 1:[1]
take a look here
https://linuxhint.com/print-command-output-ansible/
perhaps you want debug to output the result
Solution 2:[2]
Having investigated the issue further, I was able to uncover that Ansible STDOUT comparisons – using the method highlighted in the original question – is a case-sensitive process, and does not account for differences in capitalisation and casing. Instead it expects an exact match when aiming to identify the "pattern" that was being used. In my case, the execution of the command returned "true" and not "True", and so by simply modifying the expected-pattern I was able to resolve the issue. If the execution of this step is not dependent on a testing suite or CI/CD pipeline such as Atlassian Bamboo (or others), I do suggest taking a look into Andylondon's answer, which recommends registering the output of STDOUT to a variable, which can then be used to debug any issues.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | andylondon |
| Solution 2 | Vilitaria |
