如何使用ansible查找Linux主机的序列号

问题描述 投票:0回答:1

因此,对于Linux服务器序列号,我看起来有一个“内置”事实的高低,看起来如果没有自定义的dmidecode ansible模块就无法使用它。这是真的吗?我觉得奇怪的是,由于内置的​​安全事实过多,序列号不包括在内。

$ /usr/bin/ansible --version
ansible 2.4.2.0
  config file = /home/user/.ansible.cfg
  configured module search path = ['/home/user/.ansible/plugins/modules', 
u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.6.6 (r266:84292, Aug  9 2016, 06:11:56) [GCC 4.4.7 
20120313 (Red Hat 4.4.7-17)]
ansible ansible-2.x ansible-facts
1个回答
3
投票

Ansible documentation所述,收集事实是通过setup模块完成的。

要查看Ansible清单文件中定义的所有主机的所有事实:

ansible all -m setup

要查看清单文件中存在的特定Linux主机(myserver01)的序列号:

ansible -b myserver01 -m setup -a 'filter=ansible_product_serial'

对于从不在清单文件中的主机(myserver01)收集的相同事实:

ansible -b -i myserver01, all -m setup -a 'filter=ansible_product_serial'

更新了响应以包含@Henk的注释:ansible命令需要与become-b)一起运行以获取ansible_product_serial数据。如果您没有使用无密码权限提升,请添加-K

© www.soinside.com 2019 - 2024. All rights reserved.