Ansible的配置文件(more)

Ansible的一些的设置可以通过配置文件完成.在大多数场景下默认的配置就能满足大多数用户的需求,在一些特殊场景下,用户还是需要自行修改这些配置文件

读取配置文件的优先级

ansible的默认配置文件是/etc/ansible/ansible.cfg。其实ansible会按照下面的顺序查找配置文件,并使用第一个发现的配置文件。

  • ANSIBLE_CONFIG (an environment variable)
  • ansible.cfg (in the current directory)
  • .ansible.cfg (in the home directory)
  • /etc/ansible/ansible.cfg

V1.5以前的版本顺序为:

  • ansible.cfg (in the current directory)
  • ANSIBLE_CONFIG (an environment variable)
  • .ansible.cfg (in the home directory)
  • /etc/ansible/ansible.cfg

配置选项详解

到目前为止,我还没有见到一个配置项超级少,配置超级简单的配置文件;同样的,Ansible的配置文件也不简单,配置项超级多;但是,二八法则同样也适用于这些配置文件,20%的配置项决定了80%的功能,只有那20%的配置项是我们需要去关心的。所以,大家不要害怕,下面我们就将这20%常用的选项进行一一说明和总结。

defaults配置

privilege_escalation配置

配置项 说明 默认值
become 是否开启become模式 True
become_method 定义become方式 sudo
become_user 定义become方式 root
become_ask_pass 是否定义become提示密码 False