您的位置:首页 > 其它

Ansible配置详解

2019-10-07 23:59 841 查看

目录

Ansible配置详解

😄 Written by Zak Zhu

参考

配置优先级

配置文件: ansible.cfg

优先级:配置

  1. ANSIBLE_CONFIG:ansible命令会先检查该环境变量
  2. ./ansible.cfg当前执行ansible命令的目录
  3. ~/.ansible.cfg
  4. /etc/ansible/ansible.cfg默认配置文件

注意: 配置文件中所有的配置项都可以通过环境变量的方式来定义,而环境变量定义的配置项具有最高优先级,会覆盖掉所有配置文件中的配置项

上述结论, 可以从ansible.cfg文件的开头注释中看到:

# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first

配置参数说明

  • [defaults]

    #inventory = /etc/ansible/hosts
    #library = /usr/share/my_modules/
    #module_utils = /usr/share/my_module_utils/
    #remote_tmp = ~/.ansible/tmp
    #local_tmp = ~/.ansible/tmp
    #plugin_filters_cfg = /etc/ansible/plugin_filters.yml

    forks = 20 # 该值需经过测试后设定
    #poll_interval = 15
    #sudo_user = root
    #ask_sudo_pass = True
    ask_pass = False
    #transport = smart
    #remote_port = 22
    #module_lang = C
    #module_set_locale = False

    ## 使用json文件作为fact缓存后端

    gathering = smart

    fact_caching_timeout = 86400

    fact_caching = jsonfile

    fact_caching_connection = /tmp/ansible_fact_cache

    #roles_path = /etc/ansible/roles

    ## ssh过期时间

    timeout = 60

    host_key_checking = False

    ## 被控端提权的普通用户

    remote_user = ansible

    log_path = /var/log/ansible.log

  • [inventory]

    ### 与主机清单相关的配置

  • [privilege_escalation]

    become=True
    become_method=sudo
    become_user=root
    become_ask_pass=False

  • [paramiko_connection]

    ### Paramiko在RHEL6以及更早的版本中默认使用的ssh连接方式

  • [ssh_connection]

    ### OpenSSH是Ansible在RHEL7中默认使用的ssh连接方式

    ### 调优配置如下:

    ssh_args = -C -o ControlMaster=auto -o ControlPersist=10m -o StrictHostKeyChecking=no

    ## 开启pipelining,并在被控端的/etc/sudoers文件中关闭requiretty!

    pipelining = True

  • [persistent_connection]

    ### 持久连接的配置项

  • [accelerate]

    Ansible官方建议在可以使用pipelining的情况下,尽量使用pipelining而不是accelerate模式。accelerate只在如下情况下有用处:

      管理centos6或者更早的那些依然使用paramikio作为连接被控节点的场景

    1. 无法使用pipelining的场景

  • [selinux]

    ### selinux相关的配置项

  • [colors]

    ### ansible命令输出的颜色相关的配置项

  • [diff]

    ### 打印文件修改前后差异

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: