Need an assist for an ansible playbook where is am receiving error while comparing ansible value with the customer provided value.

Hi All,

I need to work on ansible role, where after the ansible module is executed I need to compare that value with the value provided by the customer.
I am able to fetch the value through ansible role however I am facing issues while comparing this value with the value provided by the customer.
Any assistance or guidance would be of great help, Thanks.

This is correct, as the values are different. So the assert task should fail.

Thanks for your reply. I modified the command ( timedatectl | grep -i “Time zone:” | sed ‘s/^ *.T/T/g’ ) to trim the space I was receiving in stdout and it resolved the issue.

Your last task shall not match due to whitespaces from the registered var. Try rewriting your assertion like this.

  • name: “Assert Similarity”

vars:

customer_val: “{{ lookup(‘file’, ‘customer-expects.txt’) | from_yaml }}”

assert:

that: “{{ customer_val == _cat.stdout | trim }}”

fail_msg: Missed

success_msg: Matched

PS: Update the formatting as required, am not using a console/system.