ansible facts组件采取设备信息

栏目: 服务器 · 发布时间: 7年前

内容简介:ansible facts组件采取设备信息

facts 组件是 ansible 用于采集被管理机器设备信息的一个功能,我们可以用 setup 模块查看机器的所有 fasct 信息,可以使用 filter 来查看指定信息。整个 facts 信息被包装在一个 JSON 格式的数据结构中。

简单了解fscts结构

$ ansible centos -m setup //输出内容过多,自行尝试

$ ansible centos -m setup -a 'filter=ansible_all_ipv4_addresses' //查看指定信息
192.168.56.102 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.56.102",
            "10.0.2.15",
            "192.168.31.14"
        ]
    },
    "changed": false
}
192.168.56.101 | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.56.101",
            "10.0.2.15",
            "192.168.31.95"
        ]
    },
    "changed": false
}

使用facter扩展facts信息

ansiblefacts 组件会判断被控制主机上是否安装有 facterruby-json|rubygem-json 包,如果存在,会自动采集信息。

centos7 facter 下载地址

facter官网下载
$ ansible centos -m shell -a 'rpm -aq rubygem-json facter'

192.168.56.102 | SUCCESS | rc=0 >>
rubygem-json-1.7.7-29.el7.x86_64
facter-2.4.1-1.el7.x86_64

192.168.56.101 | SUCCESS | rc=0 >>
rubygem-json-1.7.7-29.el7.x86_64
facter-2.4.1-1.el7.x86_64

运行 facter 模块查看 facter 信息

$ ansible 192.168.56.102 -m facter //显示内容过多,自行尝试

使用ohai扩展facts信息

ohaichef 配置管理 工具 中检测节点属性的工具, ansiblefacts 也支持 ohai 信息的采集,需要在被管理主机上安装 ohai 包。

安装ohai

国内服务器需要更换地址 RubyGems镜像-Ruby-China

更换gem sources地址为国内

$ ansible centos -m shell -a 'gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/'
192.168.56.101 | SUCCESS | rc=0 >>
https://gems.ruby-china.org/ added to sources
https://rubygems.org/ removed from sources

192.168.56.102 | SUCCESS | rc=0 >>
https://gems.ruby-china.org/ added to sources
https://rubygems.org/ removed from sources

查看gem sources地址

$ ansible centos -m shell -a 'gem sources -l'
192.168.56.102 | SUCCESS | rc=0 >>
*** CURRENT SOURCES ***

https://gems.ruby-china.org/

192.168.56.101 | SUCCESS | rc=0 >>
*** CURRENT SOURCES ***

https://gems.ruby-china.org/

安装ohai

ansible centos -m shell -a 'gem install ohai'

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Haskell

Haskell

Simon Thompson / Addison-Wesley / 1999-3-16 / GBP 40.99

The second edition of Haskell: The Craft of Functional Programming is essential reading for beginners to functional programming and newcomers to the Haskell programming language. The emphasis is on th......一起来看看 《Haskell》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

html转js在线工具
html转js在线工具

html转js在线工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具