ansible - Ansible 输出仅将一个设备写入文件
问题描述
我是 Ansible 的新手,并试图从 2 个测试设备中获取 ios_facts。正如您在输出中看到的那样,Ansible 会遍历两个设备,但只将第一个设备写入目标文件。我很确定需要得到我正在寻找的输出。有人可以告诉我还需要什么或将我推向正确的方向吗?非常感谢您提前。
主机文件
[LocationA]
1.1.1.1
2.2.2.2
神社模板:
{% for host in groups['LocationA'] %}
hostname: {{ ansible_net_hostname }}
version: {{ ansible_net_version }}
File_system: {{ ansible_net_filesystems_info }}
Neighbors: {{ansible_net_neighbors }} {{ansible_net_model}}
model: {{ansible_net_model}}
{% endfor %}
剧本-
- name: Gathering IOS facts
hosts: LocationA
connection: network_cli
gather_facts: no
tasks:
- name: Gather IOS device facts
ios_facts:
gather_subset: all
# - name: View ansible fact keys
# debug:
# var: ansible_facts.keys()
- name: output to a file
ansible.builtin.template:
src: ./templates/md5-result.j2
dest: ./devices/switch-facts.txt
newline_sequence: '\r\n'
输出-
hostname: 1.1.1.1
version: 16.12.04
File_system: {'flash:': {'spacetotal_kb': 1583952.0, 'spacefree_kb': 557316.0}}
Neighbors: {} WS-C3850-48T
model: WS-C3850-48T
hostname: 1.1.1.1
version: 16.12.04
File_system: {'flash:': {'spacetotal_kb': 1583952.0, 'spacefree_kb': 557316.0}}
Neighbors: {} WS-C3850-48T
model: WS-C3850-48T
解决方案
推荐阅读
- linux - 查询 clang 代码覆盖率和 gcov 版本
- python - 从 javascripr/浏览器调用 Python 函数
- node.js - 通过 CarboneJS 使用我自己的存储在数据库中的模板
- python - cv2.waitKey() 适用于“q”键,但不适用于任何其他键
- javascript - 如何在叶地图中显示给定半径内的标记
- sql - 不同路由器但相同调制解调器上的 SQL Server 的连接字符串
- java - Android工作室创建新意图
- android - 如何在 Android 中的 TextInputLayout 上显示边框
- ios - 协议“App”只能用作通用约束,因为它具有 Self 或关联的类型要求
- ios - Swift:将 uid = uid 的 Firestore 子集合中的数据存储到对象中