大佬教程收集整理的这篇文章主要介绍了Ansible 保存来自多个主机的输出,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到了 ansible playbook 的问题,我想将所有服务器的信息收集到一个文件中。简单地说,我需要从主机文件下指定的所有服务器收集信息。 这是我的 .yml 文件:
---
- hosts: IDrac
connection: local
name: Get system inventory
gather_facts: false
collections:
- dellemc.openmanage
tasks:
- name: Get system inventory
dellemc_get_system_inventory:
IDrac_ip: "{{ IDrac_ip }}"
IDrac_user: "root"
IDrac_password: "root"
register: result
- name: copy results locally to output file
copy:
content: "{{ result }}"
dest: "./output/system_inventory_output.Json"
delegate_to: localhost
但问题是我检查了输出文件,它只包含来自一台服务器的 Json 数据。 我一直在浏览网络,但直到现在还没有找到任何可行的解决方案......
知道如何实现这一目标吗?
谢谢!
在第二次播放中创建输出文件,并使用模板迭代所有主机。像这样:
---
- hosts: idrac
connection: local
name: Get system inventory
gather_facts: false
collections:
- dellemc.openmanage
tasks:
- name: Get system inventory
dellemc_get_system_inventory:
idrac_ip: "{{ idrac_ip }}"
idrac_user: "root"
idrac_password: "root"
register: system_inventory
- hosts: localhost
gather_facts: false
tasks:
- name: Write results to local output file
copy:
dest: "./output/system_inventory_output.json"
content: |
{% for host in groups.idrac %}
=== {{ host }} ==
{{hostvars[host].system_inventory}}
{% endfor %}
您可以选择使用 template
模块,而不是像我在这里所做的那样将模板嵌入到 content
模块的 copy
参数中。
以上是大佬教程为你收集整理的Ansible 保存来自多个主机的输出全部内容,希望文章能够帮你解决Ansible 保存来自多个主机的输出所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。