Junos Automation (Scripting)
Highlighted
Junos Automation (Scripting)

Comparing string variable content in WHEN condition in Ansible

‎04-23-2020 03:41 PM

Hi everybody,

Please consider the following set up:

MX is configured with:

roo-MX> show configuration firewall family inet | display set
set firewall family inet filter TEST1 term T1 then accept
set firewall family inet filter TEST1 term T2 then log

 

#################################################

---
- name: GETTING SHOW OUTPUT ANS STORING IT INTO VARIABLE TEST
connection: network_cli
cli_command:
command: show configuration firewall family inet filter TEST1 |display set
register: TEST
- debug:
var: TEST

- name: COMPARING
connection: network_cli
debug:
msg: " NOT COMPLIANT"
when:
- TEST.stdout != A

#############

Variable A:

---
A: "set firewall family inet filter TEST1 term T1 then accept/nset firewall family inet filter TEST1 term T2 then log"

##############################################################

TASK [STIG_ROUTER : GETTING SHOW OUTPUT ANS STORING IT INTO VARIABLE TEST] *********************************************************************************************************************
ok: [192.168.22.10]

TASK [STIG_ROUTER : debug] *********************************************************************************************************************************************************************
ok: [192.168.22.10] => {
"TEST": {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"deprecations": [
{
"msg": "Distribution Ubuntu 18.04 on host 192.168.22.10 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information",
"version": "2.12"
}
],
"failed": false,
"stdout": "set firewall family inet filter TEST1 term T1 then accept\nset firewall family inet filter TEST1 term T2 then log",
"stdout_lines": [
"set firewall family inet filter TEST1 term T1 then accept",
"set firewall family inet filter TEST1 term T2 then log"
]
}
}

TASK [STIG_ROUTER : COMPARING] *****************************************************************************************************************************************************************
ok: [192.168.22.10] => {
"msg": " NOT COMPLIANT"
}

 

#######################################

Above:

TEST.stdout=A ( the contents of A are same as contents of TEST.stdout) so when condition should be evaluated as false and assocaited task should not run. But we see task did ( msg " not compliant was printed) though when condition was false.

What am I missing here?

 

Thanks