• 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内容

     
     
  • 相关阅读:
    loglikelihood ratio 相似度
    实例详解机器学习如何解决问题
    【特征工程】特征选择与特征学习
    基于贝叶斯的文本分类实战
    转 :scikit-learn的GBDT工具进行特征选取。
    QT静态库和动态库的导出
    C#.NET为List加入扩展方法:获取唯一值
    caffe卷积层代码阅读笔记
    UVa 11300
    zoj 3882 Help Bob(zoj 2015年7月月赛)
  • 原文地址:https://www.cnblogs.com/wanstack/p/8650580.html
Copyright © 2020-2023  润新知