有没有办法在 Ansible 中运行 Cisco NX-OS Bash shell 命令而无需进入配置模式的任务?
我只想获得以下命令输出但一直失败。
bash-4.3# smartctl -a /dev/sda | egrep 'Model|Firmware|Hours'
Device Model: Micron_M600_MTFDDAT064MBF
Firmware Version: MC04
9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 17014
我使用的是下面的剧本。
- name: running the bash commands
ios_command:
commands:
- conf t
- feature bash
- run bash sudo su
- smartctl -a /dev/sda | egrep 'Model|Firmware|Hours'
register: uptime
- name: output the result
debug:
msg: uptime
- name: run the last command
ios_command:
commands: smartctl -a /dev/sda | egrep 'Model|Firmware|Hours'
register: uptime
- name: write to the file
ansible.builtin.template:
src: ./templates/9k_uptime.j2
dest: ./9k_uptime/9k_uptime.txt
newline_sequence: '\r\n'
(** 我不精通 Ansible。只是几乎不知道如何获得批量设备的输出)非常感谢任何帮助。谢谢!