ansible facts组件采取设备信息

##文章来自于:carey.akhack.com

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'

使用ohai

ansible centos -m ohai

转载于:https://my.oschina.net/careyjike/blog/914485

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值