单个文件中的 Ansible 事实 [英] Ansible facts in a single file

查看:26
本文介绍了单个文件中的 Ansible 事实的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令通过 ansible 收集服务器清单:

ansible all -m setup -a --tree 事实/

但这会在facts文件夹下为每个主机生成很多os单个文件.

我希望所有服务器都输出到一个唯一的文件中,我注意到内容类似于 json.我想稍后用它来读取 python 并使用主机名作为 python 字典的键,然后读取有关收集的每个主机的事实.

下面有类似的吗??

ansible localhost -m setup -a --tree --single-file 事实/

解决方案

此剧本将复制主机上 /tmp/ansible_facts_details.json 文件中的所有收集事实内容.您可以从控制机器(安装 Ansible 的机器)中清单文件所在的位置运行它.

  1. 运行 playbook 的命令是 ansible-playbook playbooks/gatherfacts_playbook.yaml
  2. 检查剧本语法的命令是 ansible-playbook playbooks/gatherfacts_playbook.yaml --syntax-check
  3. 运行时调试命令 ansible-playbook -vvv playbooks/gatherfacts_playbook.yaml

<块引用>

- name: 播放获取信息内容主持人:DEV1任务:- 名称:打印 ansible_facts调试:var: ansible_facts[内核"]- 名称:将可靠的事实复制到文件中.复制:内容:{{ ansible_facts }}"目标:/tmp/ansible_facts_details.json

I'm trying to collect servers inventory with ansible using the following command:

ansible all -m setup -a --tree facts/

but this is generating a lot os single files for each host under facts folder.

I would like all servers output in a unique file, I noticed the content is similar to json. I want to use it to read in python later and use the hostname as keys for the python dictionary and just read the the facts regarding each host collected.

Is there something like below??

ansible localhost -m setup -a --tree --single-file facts/

解决方案

This playbook will copy all the gather fact content in /tmp/ansible_facts_details.json file on the host machine. You can run it from location where inventory file is located in the control machine (Machine where Ansible is installed).

  1. Command to run playbook is ansible-playbook playbooks/gatherfacts_playbook.yaml
  2. Command to check playbook syntax is ansible-playbook playbooks/gatherfacts_playbook.yaml --syntax-check
  3. Command to do runtime debug ansible-playbook -vvv playbooks/gatherfacts_playbook.yaml

- name: Play to get the gathre facts content
  hosts: DEV1
  tasks:
  - name: print ansible_facts
    debug:
     var: ansible_facts["kernal"]
  - name: Copy ansible facts to a file.
    copy:
     content: "{{ ansible_facts }}"
     dest: /tmp/ansible_facts_details.json

这篇关于单个文件中的 Ansible 事实的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆