Description of my problem: Ansible code should be triggered during an
interface flapping with cisco nessus device. It should fetch the time of
nessus device(show clock) and try to pull the past 15 minutes from the
"show logging" output of nessus device.
Ansible experts, I need to help to manipulate the time to get past 15
minutes from show logging. Below s the code written so far.
cat interfaceflapping.yml
--- - name: Cisco NXOS hosts: all connection: network_cli gather_facts:
false vars: - cmdlist: sh clock - ansible_python_interpreter:
/usr/bin/python3 - ansible_network_os: nxos tasks: - name: Execute command
nxos_command: commands: "{{ cmdlist }}" register: output - set_fact: arr:
"{{ output.stdout_lines[0][1].split() }}" - debug: msg: "{{ arr[0] }}" -
name: print variable set_fact: my_string_var: "{{ arr[0].split(':') |
default('') }}" - debug: msg: "{{my_string_var}}" - name: Execute command
nxos_command: commands: sh logging | include 2/3 register: output1 - debug:
msg: "{{ output1 }}" when: output1.stdout is search(my_string_var)
```ansible ================== output as below [LABPC@lab-jump-host dow]$
ansible-playbook interfaceflapping.yml -i inventory1.txt --limit nxos
--verbose Using /etc/ansible/ansible.cfg as config file PLAY [Cisco NXOS]
******************************************************************************************************************************************************************************************
TASK [Execute command]
*************************************************************************************************************************************************************************************
ok: [nxos] => {"changed": false, "stdout": ["Time source is
NTP\n18:50:15.681 UTC Sat Jul 02 2022"], "stdout_lines": [["Time source is
NTP", "18:50:15.681 UTC Sat Jul 02 2022"]]} TASK [set_fact]
********************************************************************************************************************************************************************************************
ok: [nxos] => {"ansible_facts": {"arr": ["18:50:15.681", "UTC", "Sat",
"Jul", "02", "2022"]}, "changed": false} TASK [debug]
***********************************************************************************************************************************************************************************************
ok: [nxos] => { "msg": "18:50:15.681" } TASK [print variable]
**************************************************************************************************************************************************************************************
ok: [nxos] => {"ansible_facts": {"my_string_var": ["18", "50", "15.681"]},
"changed": false} TASK [debug]
***********************************************************************************************************************************************************************************************
ok: [nxos] => { "msg": [ "18", "50", "15.681" ] } TASK [Execute command]
*************************************************************************************************************************************************************************************
ok: [nxos] => {"changed": false, "stdout": [""], "stdout_lines": [[""]]}
TASK [debug]
***********************************************************************************************************************************************************************************************
fatal: [nxos]: FAILED! => {"msg": "The conditional check 'output1.stdout is
search(my_string_var)' failed. The error was: Unexpected templating type
error occurred on ({% if output1.stdout is search(my_string_var) %} True {%
else %} False {% endif %}): unhashable type: 'list'\n\nThe error appears to
be in '/home/LABPC/gomathi/dow/root/dow/interfaceflapping.yml': line 32,
column 8, 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"}
PLAY RECAP
*************************************************************************************************************************************************************************************************
nxos : ok=6 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
============== PLZ HELP ME TO GET THE PAST 15 MINUTES OUTPUT FROM SHOW
LOGGING. I HAVE HARDCODED THE INTERFACE NUMBER AS 2/3 .
<https://stackoverflow.com/questions/tagged/ansible>
--
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/98c15c63-f8ea-4623-b7b3-eecab0a206cdn%40googlegroups.com.