Facts 是用来采集目标系统信息的,具体是用setup模块来采集得。

使用setup模块来获取目标系统信息

ansible hostname -m setup

仅显示与ansible相关的内存信息

ansible all -m setup -a 'filter=ansible_*_mb'

常用的变量


  • ansible_distribution
  • ansible_distribution_release
  • ansible_distribution_version
  • ansible_fqdn
  • ansible_hostname
  • ansible_os_family
  • ansible_pkg_mgr
  • ansible_default_ipv4.address
  • ansible_default_ipv6.address

关闭自动采集


- hosts: whatever
gather_facts: no

自定义目标系统facts


在远程主机/etc/ansible/facts.d/目录下创建.fact 结尾的文件,也可以是json、ini 或者返回json 格式数据的可执行文件,这些将被作为远程主机本地的facts 执行

 
 

可以通过{{ ansible_local.preferences.test.h }}方式来使用该变量

 
 

Facts 使用文件作为缓存


修改ansible配置文件

# /etc/ansible/ansible.cfg
fact_caching = jsonfile
fact_caching_connection = /tmp/facts_cache mkdir /tmp/facts_cache
chmod 777 /tmp/facts_cache/

运行playbook

ansible-playbook facts.yml

查看缓存目录

 
 

上述文件中存储着json序列化的facts数据

Facts 使用redis作为缓存


安装redis

yum -y install redis-server
easy_install pip
pip install redis

配置redis,使用密码登陆

#vim /etc/redis.conf
requirepass "admin"

启动redis

service redis start

修改ansible配置文件

# /etc/ansible/ansible.cfg
gathering = smart
fact_caching = redis
fact_caching_timeout = 86400
fact_caching_connection = localhost:6379:0:admin

运行playbook

ansible-playbook facts.yml

查看redis内容

 
 

Facts 使用memcached作为缓存


安装 memcached

yum install memcached
easy_install pip
pip install python-memcached

启动memcached

/usr/bin/memcached -d -u memcached

修改ansible配置文件

# /etc/ansible/ansible.cfg
gathering = smart
fact_caching = memcached
fact_caching_timeout = 86400
fact_caching_connection = localhost:11211

查看memcached内容

 
 

最新文章

  1. 【Beta】Daily Scrum Meeting第五次
  2. .Net语言 APP开发平台——Smobiler学习日志:快速在手机上实现n×m形式的菜单(IconMenuView)
  3. psutil一个基于python的跨平台系统信息跟踪模块
  4. Docker容器操作中常用命令集合
  5. TimeQuest 静态时序分析 基本概论
  6. Python - Tips
  7. Day Six(Beta)
  8. HTML5学习之拖放(十)
  9. Codeforces Round #235 (Div. 2) A. Vanya and Cards
  10. WinRT知识积累2之MessageDialog应用代码
  11. const char* <----- > string
  12. LINQ之路系列
  13. Android 添加、移除和判断 桌面快捷方式图标
  14. HDU 3835 R(N)(枚举)
  15. ZOJ 3777-Problem Arrangement(状压DP)
  16. 洛谷 P1564 膜拜
  17. 【总结】Java异常分类
  18. linux定时任务crontab 实现如何每秒执行一次!
  19. spring注解第05课 FactoryBean
  20. C#-老生常谈的 值类型与引用类型

热门文章

  1. (C++) Assertion failed: !"Bad error code", file VMem.c, line 715
  2. android ListView SimpleAdapter 带图片
  3. property函数的使用
  4. #if defined(__cplusplus)
  5. 文本文件显示 删除文本文件前n个字符
  6. SQL Server 使用 Pivot 和 UnPivot 实现行列转换
  7. 19. Remove Nth Node From End of List(移除倒数第N的结点, 快慢指针)
  8. ZOJ - 3229 Shoot the Bullet (有源汇点上下界最大流)
  9. 转载:逻辑回归的python实现
  10. RBAC权限模型——项目实战