zoukankan      html  css  js  c++  java
  • ansible配置文件

    ansible配置文件

    /etc/ansible
    ansible.cfg
    hosts
    roles

    ansible.cfg:ansible执行需求的全局性,默认的主配置文件
    hosts:默认的主机资产清单文件
    roles:角色文件

    查看配置文件

    [root@iZj6cf244ucbfj060qys19Z ~]# ansible --version
    ansible 2.4.1.0
      config file = None
      configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python2.7/site-packages/ansible-2.4.1.0-py2.7.egg/ansible
      executable location = /usr/bin/ansible
      python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
    

    设置主配置文件

    未生效

    [root@iZj6cf244ucbfj060qys19Z ~]# export ANSIBLE_CONFIG=/root/test.cfg
    [root@iZj6cf244ucbfj060qys19Z ~]# ansible --version
    ansible 2.4.1.0
      config file = None
      configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python2.7/site-packages/ansible-2.4.1.0-py2.7.egg/ansible
      executable location = /usr/bin/ansible
      python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
    

    创建文件

    mkdir /etc/ansible
    vim /etc/ansible/ansible.cfg
    [root@iZj6cf244ucbfj060qys19Z usr]# cat /etc/ansible/ansible.cfg
    [defaults]
    inventory = /tmp/hosts
    [ssh_connection]
    ssh_args = -o StrictHostKeyChecking=no
    cat /tmp/hosts
    

    hosts文件配置

    [test]
    172.31.187.202:22 ansible_ssh_user=root ansible_ssh_pass='123456Aa'
    

    查看配置文件,为什么就变更过来了

    [root@iZj6cf244ucbfj060qys19Z usr]# ansible --version
    ansible 2.4.1.0
      config file = /etc/ansible/ansible.cfg
      configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
      ansible python module location = /usr/lib/python2.7/site-packages/ansible-2.4.1.0-py2.7.egg/ansible
      executable location = /usr/bin/ansible
      python version = 2.7.5 (default, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
    

    ansible读取配置文件的优先级

    ANSIBLE_CONFIG
    ./ansible.cfg
    ~/ansible.cfg
    /etc/ansible/ansible.cfg
    

    ansible 读取hosts文件的优先级与上相同

    #注释/etc/ansible/ansible.cfg中的hosts文件配置
    [root@iZj6cf244ucbfj060qys19Z usr]# cat /etc/ansible/ansible.cfg
    [defaults]
    #inventory = /tmp/hosts
    [ssh_connection]
    ssh_args = -o StrictHostKeyChecking=no
    #显示结果如下
    [root@iZj6cf244ucbfj060qys19Z ~]# ansible test --list-host
     [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source
    
     [WARNING]: No inventory was parsed, only implicit localhost is available
    
     [WARNING]: Could not match supplied host pattern, ignoring: all
    
     [WARNING]: provided hosts list is empty, only localhost is available
    
     [WARNING]: Could not match supplied host pattern, ignoring: test
    
     [WARNING]: No hosts matched, nothing to do
    
      hosts (0):
    

    复制并再次检测

    [root@iZj6cf244ucbfj060qys19Z ~]# cp /tmp/hosts /etc/ansible/
    #出现主机信息
    [root@iZj6cf244ucbfj060qys19Z ~]# ansible test --list-hosts
      hosts (1):
        172.31.187.202
    
  • 相关阅读:
    3.14周末作业
    3.13作业
    文件处理
    字符编码
    基本数据类型总结
    基本数据类型--------------------集合set()
    python入门009
    作业009
    python入门008
    作业008
  • 原文地址:https://www.cnblogs.com/anyux/p/11979914.html
Copyright © 2011-2022 走看看