Kod*_*ode 4 ansible ansible-facts
我正在使用 Ansible / Ansible Tower,并且想确定我的 Windows 主机上有哪些可用信息。该文档指出我可以运行以下命令:
ansible hostname -m setup
Run Code Online (Sandbox Code Playgroud)
我如何将其合并到从 Ansible Tower 运行的剧本中,以便我可以从主机收集信息?
以下是根据所提供的帮助当前的剧本:
ansible hostname -m setup
Run Code Online (Sandbox Code Playgroud)
但是,运行此命令会产生以下错误:
# This play outputs the facts of the Windows targets in scope
- name: Gather Windows Facts
hosts: "{{ target }}"
gather_facts: yes
tasks:
- setup:
register: ansible_facts
- debug: item
with_dict: ansible_facts
Run Code Online (Sandbox Code Playgroud)
使用gather_facts默认情况下为 true 的值。相当于运行setup模块。
- hosts: ....
gather_facts: yes
Run Code Online (Sandbox Code Playgroud)
事实保存在 ansible 变量中以在剧本中使用。查看系统概况
有很多方法可以显示 ansible 事实。为了让您了解其工作原理,请尝试以下操作:
- hosts: 127.0.0.1
gather_facts: true
tasks:
- setup:
register: ansible_facts
- debug: item
with_dict: ansible_facts
Run Code Online (Sandbox Code Playgroud)