Ansible-Playbook for fetch D-link switch Serial Number

621 views
Skip to first unread message

Rajdeep Rathod

unread,
Jul 26, 2022, 3:43:22 AM7/26/22
to Ansible Project
Hello,

I have multiple network switch. i want to get serial number using ansible play book.
here i have tried but not succeed.

In below example i have output of so many lines i have get only Serial Number Please help me...

test.yml

---

- name: switch
  hosts: switch
  gather_facts: false

  tasks:
    - name: switch serial number check
      ios_command:
        commands: show system
      register: output

    - name: print output
      debug:
        var: output.stdout_lines

Output :
PLAY [switch] ***********************************************************************

TASK [switch serial number check] ***************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 18.04 on host 10.99.8.98 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. This feature will be removed in version 2.12. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
ok: [10.99.8.98]

TASK [print output] *****************************************************************
ok: [10.99.8.98] => {
    "output.stdout_lines": [
        [
            "Model Name                  : DIS-F200-10PS",
            "",
            "System Description          : Industrial 8-P GbE RJ45 + 2 GbE RJ45/SFP Combo L2 Plus Managed PoE Switch",
            "",
            "Location                    : CCC",
            "",
            "Contact                     : ",
            "",
            "System Name                 : Stand-SWI-01",
            "",
            "System Date                 : 2022-07-26T13:07:05+05:30",
            "",
            "System Uptime               : 1d 17:06:28",
            "",
            "Bootloader Version          : v1.20",
            "",
            "Firmware Version            : v7.10.2569 2020-05-15",
            "",
            "Hardware Version            : v1.01",
            "",
            "Mechanical Version          : v1.01",
            "",
            "Serial Number               : RVF21J2000123",
            "",
            "MAC Address                 : #############",
            "",
            "Memory                      : Total=51778 KBytes, Free=32454 KBytes, Max=31624 KBytes",
            "",
            "FLASH                       : 0x40000000-0x41ffffff, 512 x 0x10000 blocks",
            "",
            "Powers status               : Normal",
            "",
            "Powers                      : PWR_1.0V:0.98V; PWR_3.3V:3.29V; PWR_2.5V:2.60V; PWR_1.8V:1.93V",
            "",
            "Temperature status          : Normal",
            "",
            "Temperature 1               : 46(C) ; 114(F)",
            "",
            "Temperature 2               : 49(C) ; 120(F)"
        ]
    ]
}

PLAY RECAP **************************************************************************
10.99.8.98                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0



Reply all
Reply to author
Forward
0 new messages