I have a query regarding how to print difference between an ansible output and customer expected value.

12 views
Skip to first unread message

Marian Saldhana

unread,
Jan 21, 2022, 4:01:36 AM1/21/22
to Ansible Project

As per my role [root@ansible-master tasks]# cat main.yml

--- # tasks file for Security_Info_Tab8 - shell: grep -v ^\# /etc/xinetd.d/telnet | grep -i disable register: telnet_setting changed_when: false - assert: that: - lookup('file', 'customer-expects.txt') == telnet_setting.stdout fail_msg: missed success_msg: matched

+++

The customer-expects.txt mentioned is [root@ansible-master /]# cat customer-expects.txt

root

+++

When the playbook is run [root@ansible-master /]# ansible-playbook tab8.role.yml -v the below output is displayed as expected

Using /etc/ansible/ansible.cfg as config file PLAY [This output is for Tab-8 of Function Design document] ***************************************************************************** TASK [Gathering Facts] ****************************************************************************************************************** ok: [ansible-client1] TASK [telnet_setting_tab8 : shell] ****************************************************************************************************** ok: [ansible-client1] => {"changed": false, "cmd": "grep -v ^\\# /etc/xinetd.d/telnet | grep -i disable", "delta": "0:00:00.009030", "end": "2022-01-21 15:08:03.157469", "rc": 0, "start": "2022-01-21 15:08:03.148439", "stderr": "", "stderr_lines": [], "stdout": "disable no", "stdout_lines": ["disable no"]} TASK [telnet_setting_tab8 : assert] ***************************************************************************************************** fatal: [ansible-client1]: FAILED! => { "assertion": "lookup('file', 'customer-expects.txt') == telnet_setting.stdout", "changed": false, "evaluated_to": false, "msg": "missed" } PLAY RECAP ****************************************************************************************************************************** ansible-client1 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

+++

As per the output its Ansible value does not match the customer expected value (this is what we are expecting), however I need to go a step further and print difference (output) of these two values within the same role. Any suggestion or advise would be of great assistance.

Evan Hisey

unread,
Jan 22, 2022, 12:59:19 PM1/22/22
to Ansible Project
If I am reading this correctly the text file is just "root". This will never match the telnet.setting, as is it will be either "disable no" or "disable yes". Is this the intended comparision?
Reply all
Reply to author
Forward
0 new messages