问题描述
我正在提取网络交换机接口信息,例如接口名称、管理状态、描述等,并将这些值解析为单个 .csv 文件,但它似乎是覆盖文件而不是附加文件,如果我在这里做错了什么,请告诉我吗?或者有更好的方法来实现这一点,这是我的剧本。
---
- name: NXOS interfaces operation status
hosts: NXOS
connection: local
gather_facts: false
tasks:
- name: discover NXOS interfaces
nxos_command:
commands:
- show run | grep ignore-case interface | exclude feature | exclude source | exclude destination | exclude logging
register: interface_names
- name: Get the interfaces stats
nxos_command:
commands:
# Full interface operational status
# - command: show interface {{ item.split(' ')[1] }}
# Interface name
- command: show interface {{ item.split(' ')[1] }} | head lines 1 | awk '{ print $1 }'
# Interface description
- command: show interface {{ item.split(' ')[1] }} | grep "Description"
# Interface operation status:
- command: show interface {{ item.split(' ')[1] }} | head lines 1 | awk '{ print $3}'
# Interface admin-status
- command: show interface {{ item.split(' ')[1] }} | grep "admin state" | awk '{ print $4 }'
# Interface MTU size
- command: show interface {{ item.split(' ')[1] }} | grep "MTU" | awk '{ print $2 }'
# Loop over the interfaces output from the prevIoUs task
loop: "{{ interface_names.stdout_lines[0] }}"
register: interfaces_stats
- name: Saving interfaces facts for NXOS
copy:
content: |
#jinja2: lstrip_blocks: True,trim_blocks: True
{{ inventory_hostname }}
Interface name,Interface description,Interface operational-status,Interface admin-status,Interface MTU size
{{ item.stdout_lines[0] }},{{ item.stdout_lines[1] }},{{ item.stdout_lines[2] }},{{ item.stdout_lines[3] }},{{ item.stdout_lines[4] }}
dest: /opt/ansible/vsansible/info/{{ inventory_hostname }}_info.csv
with_items:
- '{{ interfaces_stats.results }}'
Interface name,Interface MTU size
[u'mgmt0'],[u'Description: -sw01-Gig0/39'],[u'up'],[u'up,'],1500
请指教。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)