Ansible 小手册系列 十二(Facts)
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内容

Ansible 小手册系列 十二(Facts)的更多相关文章
- Ansible 小手册系列 十四(条件判断和循环)
条件判断 When 语句 在when 后面使用Jinja2 表达式,结果为True则执行任务. tasks: - name: "shut down Debian flavored syste ...
- Ansible 小手册系列 十九(常见指令表)
Play 指令 说明 accelerate 开启加速模式 accelerate_ipv6 是否开启ipv6 accelerate_port 加速模式的端口 always_run any_error ...
- Ansible 小手册系列 十八(Lookup 插件)
file:获取文件内容 --- - hosts: all vars: contents: "{{ lookup('file', '/etc/foo.txt') }}" tasks: ...
- Ansible 小手册系列 十(包含和角色)
一.包含 (include) 使用include模块来包含foo文件 tasks: - include: foo.yml --- foo.yml - name: test foo command: e ...
- Ansible 小手册系列 十六(Playbook Debug)
debug模块在执行期间打印语句,并且可用于调试变量或表达式,而不必停止playbook. 打印自定义的信息 - debug: msg="System {{ inventory_hostna ...
- Ansible 小手册系列 十五(Blocks 分组)
当我们想在满足一个条件下,执行多个任务时,就需要分组了.而不再每个任务都要用when. tasks: - block: - command: echo 1 - shell: echo 2 - raw: ...
- Ansible 小手册系列 七(Ad-hoc)
Ansible提供两种方式去完成任务,一是 ad-hoc 命令,一是写 Ansible playbook.前者可以解决一些简单的任务, 后者解决较复杂的任务. ad hoc——临时的,在ansible ...
- Ansible 小手册系列 二十(经常遇到的问题)
(1). 怎么为任务设置环境变量? - name: set environment shell: echo $PATH $SOME >> /tmp/a.txt environment: P ...
- Ansible 小手册系列 十七(特性模块)
异步操作和轮询 --- # Requires ansible 1.8+ - name: 'YUM - fire and forget task' yum: name=docker-io state=i ...
随机推荐
- Eclipse下创建Maven项目(转)
原文出自:http://www.cnblogs.com/hongwz/p/5456616.html 1.新建Maven项目 1.1 File -> New -> Other 1.2 选择M ...
- linux下多线程之pthread_detach(pthread_self())
写个碰到的问题,记录下自己的技术之路点滴pthread_detach(pthread_self())linux线程执行和windows不同,pthread有两种状态joinable状态和unjoina ...
- 【分库分表】sharding-jdbc实践—分库分表入门
一.准备工作 1.准备三个数据库:db0.db1.db2 2.每个数据库新建两个订单表:t_order_0.t_order_1 DROP TABLE IF EXISTS `t_order_x`; CR ...
- 高可用Mysql架构_Mycat集群部署(HAProxy + 两台Mycat+Mysql双主双从)
既然大家都知道了Mysql分布式在大型网站架构中的作用,在这里就不再阐述.本片博客文章是基于我曾经搭建过的一个Mysql集群基础上实现的,实现过双主热备.读写分离.分库分表. 博客链接:http:// ...
- Qt+VS编译出错:Two or more files with the name of moc_Geometry.cpp will produce outputs to the same location
warning MSB8027: Two or more files with the name of moc_Geometry.cpp will produce outputs to the sam ...
- MR案例:WordCount改写
请参照wordcount实现一个自己的MapReduce,需求为: a. 输入文件格式: xxx,xxx,xxx,xxx,xxx,xxx,xxx b. 输出文件格式: ...
- 内核启动时在挂载ubi文件系统时提示UBIFS error (ubi0:0 pid 1): ubifs_read_superblock: min. I/O unit mismatch
一.背景 1.1 笔者机器的内核错误信息如下: UBIFS error (ubi0:0 pid 1): ubifs_read_superblock: min. I/O unit mismatch: 2 ...
- linux中__weak关键字的作用
答:1.可以重新定义同名函数或变量而编译时不报错
- POJ_1703 并查集应用
通过这题基本完整理解了并查集的构建和使用.很轻巧的一种数据结构. 本题的方法值得注意:并没有直接构建两个帮派的集合,而是构建: 关系确认集合+若干单元素集(也即未确认帮派的初始状态)并辅助一个rel数 ...
- Caffe学习笔记(一):Caffe架构及其模型解析
Caffe学习笔记(一):Caffe架构及其模型解析 写在前面:关于caffe平台如何快速搭建以及如何在caffe上进行训练与预测,请参见前面的文章<caffe平台快速搭建:caffe+wind ...