ansible - 从 ansible 输出中删除 u'
问题描述
我从运行我的剧本中得到的输出有问题。我怎样才能把调试输出 -H/W Version : 1.0
变成HW Version: 1.0
以及如何清理输出文件以删除 u' 和 []
more /tmp/sw-facts
Hostname: switch Version: 5.2(1)N1(3) Hardware: [u'H/W Version : 1.0'] Serial: 000000000
PLAY [研究]
TASK [Stage 1 收集版本和硬件信息] ok: [switch]
TASK [Stage 2 collect ansible fact] ok: [switch]
任务 [第 3 阶段验证网络设备的输出] ok: [switch] => msg: - - 'H/W Version : 1.0' - 5.2(1)N1(3)
TASK [格式化后将一些事实写入磁盘] ok: [switch]
---
# This playbook will retrieve version & hw info from Nexus switches
- name: Research
hosts: lab
gather_facts: false
tasks:
- name: Stage 1 gathering version & HW info
nxos_command:
commands:
- "show sprom sup | inc 'H/W Version'"
register: output
- name: Stage 2 collect ansible facts
nxos_facts:
gather_subset: hardware
register: version
- name: Stage 3 validating output from network device
debug:
msg:
- "{{ output.stdout }}"
- "{{ ansible_net_version }}"
- name: write some facts to disk after formatting
copy:
content: |
#jinja2: lstrip_blocks: True
{% for host in groups['lab'] if hostvars[host]['ansible_net_hostname'] is defined %}
Hostname: {{ hostvars[host].ansible_net_hostname }} Version: {{ hostvars[host].ansible_net_version }} Hardware: {{ hostvars[host].output.stdout }} Serial: {{ hostvars[host].ansible_ne$
{% endfor %}
dest: /tmp/sw-facts
run_once: yes
预先感谢您的任何帮助
解决方案
我将 nxos_command 修改为:“show sprom sup | inc 'H/W Version' | cut -c 19-22”
推荐阅读
- bash - 从外部驱动器复制到 Box 文件夹的 Bash 脚本
- authentication - 如何在代理和重定向环境中捕获 HTTP 流量
- swift - Xcode || 仅在发布模式而不是在调试模式下添加 swift 包以避免增加编译时间
- google-apps-script - 通过宏/脚本在 GoogleSheets 中折叠数据透视表列
- php - PHP 项目清理
- javascript - 在 javascript 中使用 dropzone.js 或普通 js 处理 csv
- c# - 寻找一种使用和异步成为朋友的方法
- api - 美国县和美国城市的自动完成 API 文本框
- ffmpeg - ffmpeg 将 Windows 7 桌面流式传输到 Youtube 给出无效参数
- firebase - 无法在 macOS 上安装 firebase 工具 cli