Hi,
Below is the output of a command i executed in cisco router. I wrote a TASK
to extract only 'isr4300-universalk9.16.15.04.SPA.bin' using Regex from the
output and put in a custom variable. Then i ran ios_facts module and one
of the pre-defined variable in ios_facts is ansible_net_version. The output
of that is 16.15.04.
Then i wrote a TASK to check if contents of ansible_net_version is present
in custom variable (as you can see below, it is) but below is the error iam
getting. I tried using 'int' filter but didn't help. When i give a set of
characters in palce of pre-defined variable or a custom variable, the when
conditional works. Why isi it not working and how can i fix it?
*ERROR:*
TASK [debug]
***************************************************************************************************************************************************************
[WARNING]: conditional statements should not include jinja2 templating
delimiters such as {{ }} or {% %}. Found: '{{ ansible_net_version | int }}'
in ios_image1.stdout[0]
fatal: [ROUTERTEST]: FAILED! => {"msg": "The conditional check ''{{
ansible_net_version | int }}' in ios_image1.stdout[0]' failed. The error
was: error while evaluating conditional ('{{ ansible_net_version | int }}'
in ios_image1.stdout[0]): 'ansible.utils.unsafe_proxy.AnsibleUnsafeText
object' has no attribute 'stdout'\n\nThe error appears to be in
'/root/router3.yaml': line 48, column 9, but may\nbe elsewhere in the file
depending on the exact syntax problem.\n\nThe offending line appears to
be:\n\n\n - debug:\n ^ here\n"}
*OUTPUT OF COMMAND AS SHOWN IN ROUTER:*
ROUTER#sh flash: | i SPA.bin
4 642363156 Aug 25 2021 23:24:43.0000000000 +00:00
/bootflash/isr4300-universalk9.16.15.04.SPA.bin
161 588714445 Jan 09 2021 14:38:08.0000000000 +00:00
/bootflash/isr4300-universalk9.16.09.09.SPA.bin
*SCRIPT:*
tasks:
- ios_facts:
- name: GATHER SHOW VERSION
ios_command:
commands: "sh flash: | i SPA.bin"
register: show_image
- set_fact:
ios_image1: "{{ show_image.stdout_lines[0][0] |
regex_findall('bootflash/(.*)') | first }}"
- debug:
msg:
- "comparison successful"
when:
- "'{{ ansible_net_version }}' in ios_image1.stdout[0]"
Regards,
Vikram
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/979a4d21-accc-4bdc-a5a4-f629abb404cdn%40googlegroups.com.