ansible.cfg配置详解



ansible.cfg配置详解

一.简单配置

1[defaults]
2inventory = /etc/ansible/hosts
3sudo_user=root
4remote_port=22
5host_key_checking=False
6remote_user=root
7log_path=/var/log/ansible.log
8module_name=command
9private_key_file=/root/.ssh/id_rsa
10no_log:True

二.详细配置

1# config file for ansible -- http://ansible.com/
2# ==============================================
3
4# 几乎所有的参数都可以在 ansible-playbook 中被覆盖
# 或使用命令行标志。 ansible 将读取 ANSIBLE_CONFIG,
# ansible.cfg 在当前工作目录,.ansible.cfg 在
# 主目录或 /etc/ansible/ansible.cfg,无论哪个
# 先找到
9
10[defaults] --->通用默认配置
11
12# some basic default values...
13
14inventory = /etc/ansible/hosts 这个是默认库文件位置,脚本,或者存放可通信主机的目录
15#library = /usr/share/my_modules/ Ansible默认搜寻模块的位置
16remote_tmp = $HOME/.ansible/tmp Ansible 通过远程传输模块到远程主机,然后远程执行,执行后在清理现场.在有些场景下,你也许想使用默认路径希望像更换补丁一样使用
17pattern = * 如果没有提供“hosts”节点,这是playbook要通信的默认主机组.默认值是对所有主机通信
18forks = 5 在与主机通信时的默认并行进程数 ,默认是5d
19poll_interval = 15 当具体的poll interval 没有定义时,多少时间回查一下这些任务的状态, 默认值是5
20sudo_user = root sudo使用的默认用户 ,默认是root
21#ask_sudo_pass = True 用来控制Ansible playbook 在执行sudo之前是否询问sudo密码.默认为no
22#ask_pass = True 控制Ansible playbook 是否会自动默认弹出密码
23transport = smart 通信机制.默认 值为’smart’。如果本地系统支持 ControlPersist技术的话,将会使用(基于OpenSSH)‘ssh’,如果不支持讲使用‘paramiko’.其他传输选项包括‘local’, ‘chroot’,’jail’等等
24#remote_port = 22 远程SSH端口。 默认是22
25module_lang = C 模块和系统之间通信的计算机语言,默认是C语言
26
27# plays will gather facts by default, which contain information about
28# the remote system.
29#
30# smart - gather by default, but don't regather if already gathered
31# implicit - gather by default, turn off with gather_facts: False
32# explicit - do not gather by default, must say gather_facts: True
33gathering = implicit 控制默认facts收集(远程系统变量). 默认值为’implicit’, 每一次play,facts都会被收集
34
35# additional paths to search for roles in, colon separated
36#roles_path = /etc/ansible/roles roles 路径指的是’roles/’下的额外目录,用于playbook搜索Ansible roles
37
38# uncomment this to disable SSH key host checking
39#host_key_checking = False 检查主机密钥
40
41# change this for alternative sudo implementations
42sudo_exe = sudo 如果在其他远程主机上使用另一种方式执sudu操作.可以使用该参数进行更换
43
44# what flags to pass to sudo 传递sudo之外的参数
45#sudo_flags = -H
46
47# SSH timeout SSH超时时间
48timeout = 10
49
50# default user to use for playbooks if user is not specified
51# (/usr/bin/ansible will use current user as default)
52#remote_user = root 使用/usr/bin/ansible-playbook链接的默认用户名,如果不指定,会使用当前登录的用户名
53
54# logging is off by default unless this path is defined
55# if so defined, consider logrotate
56#log_path = /var/log/ansible.log 日志文件存放路径
57
58# default module name for /usr/bin/ansible
59#module_name = command ansible命令执行默认的模块
60
61# use this shell for commands executed under sudo
62# you may need to change this to bin/bash in rare instances
63# if sudo is constrained
64#executable = /bin/sh 在sudo环境下产生一个shell交互接口. 用户只在/bin/bash的或者sudo限制的一些场景中需要修改
65
66# if inventory variables overlap, does the higher precedence one win
67# or are hash values merged together? The default is 'replace' but
68# this can also be set to 'merge'.
69#hash_behaviour = replace 特定的优先级覆盖变量
70
71# list any Jinja2 extensions to enable here:
72#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n 允许开启Jinja2拓展模块
73
74# if set, always use this private key file for authentication, same as
75# if passing --private-key to ansible or ansible-playbook
76#private_key_file = /path/to/file 私钥文件存储位置
77
78# format of string {{ ansible_managed }} available within Jinja2
79# templates indicates to users editing templates files will be replaced.
80# replacing {file}, {host} and {uid} and strftime codes with proper values.
81ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host} 这个设置可以告知用户,Ansible修改了一个文件,并且手动写入的内容可能已经被覆盖.
82
83# by default, ansible-playbook will display "Skipping [host]" if it determines a task
84# should not be run on a host. Set this to "False" if you don't want to see these "Skipping"
85# messages. NOTE: the task header will still be shown regardless of whether or not the
86# task is skipped.
87#display_skipped_hosts = True 显示任何跳过任务的状态 ,默认是显示
88
89# by default (as of 1.3), Ansible will raise errors when attempting to dereference
90# Jinja2 variables that are not set in templates or action lines. Uncomment this line
91# to revert the behavior to pre-1.3.
92#error_on_undefined_vars = False 如果所引用的变量名称错误的话, 将会导致ansible在执行步骤上失败
93
94# by default (as of 1.6), Ansible may display warnings based on the configuration of the
95# system running ansible itself. This may include warnings about 3rd party packages or
96# other conditions that should be resolved if possible.
97# to disable these warnings, set the following value to False:
98#system_warnings = True 允许禁用系统运行ansible相关的潜在问题警告
99
100# by default (as of 1.4), Ansible may display deprecation warnings for language
101# features that should no longer be used and will be removed in future versions.
102# to disable these warnings, set the following value to False:
103#deprecation_warnings = True 允许在ansible-playbook输出结果中禁用“不建议使用”警告
104
105# (as of 1.8), Ansible can optionally warn when usage of the shell and
106# command module appear to be simplified by using a default Ansible module
107# instead. These warnings can be silenced by adjusting the following
108# setting or adding warn=yes or warn=no to the end of the command line
109# parameter string. This will for example suggest using the git module
110# instead of shelling out to the git command.
111# command_warnings = False 当shell和命令行模块被默认模块简化的时,Ansible 将默认发出警告
112
113
114# set plugin path directories here, separate with colons
115action_plugins = /usr/share/ansible_plugins/action_plugins
116callback_plugins = /usr/share/ansible_plugins/callback_plugins
117connection_plugins = /usr/share/ansible_plugins/connection_plugins
118lookup_plugins = /usr/share/ansible_plugins/lookup_plugins
119vars_plugins = /usr/share/ansible_plugins/vars_plugins
120filter_plugins = /usr/share/ansible_plugins/filter_plugins
121
122# by default callbacks are not loaded for /bin/ansible, enable this if you
123# want, for example, a notification or logging callback to also apply to
124# /bin/ansible runs
125#bin_ansible_callbacks = False 用来控制callback插件是否在运行 /usr/bin/ansible 的时候被加载. 这个模块将用于命令行的日志系统,发出通知等特性
126
127
128# don't like cows? that's unfortunate.
129# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
130#nocows = 1 默认ansible可以调用一些cowsay的特性 开启/禁用:0/1
131
132# don't like colors either?
133# set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1
134#nocolor = 1 输出带上颜色区别, 开启/关闭:0/1
135
# 用于验证 SSL 证书的 CA 证书路径。 这条路
# 应该存在于控制节点上,而不是目标节点上
#常见位置:
139# RHEL/CentOS: /etc/pki/tls/certs/ca-bundle.crt
140# Fedora : /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
141# Ubuntu : /usr/share/ca-certificates/cacert.org/cacert.org.crt
142#ca_file_path =
143
# 获取 url 时使用的 http 用户代理字符串。 一些网络服务器
# 操作员阻止默认的 urllib 用户代理,因为它经常使用
# 通过恶意攻击/脚本,所以我们将其设置为独特的
# 避免问题。
148#http_user_agent = ansible-agent
149
# 如果设置为持久类型(不是“memory”,例如“redis”)事实值
将存储以前在 Ansible 中运行的 #。 这在以下情况下可能很有用
# 想要使用,例如,来自一组服务器的 IP 信息
# 无需在同一个剧本运行中与他们交谈即可获得他们的
# 当前 IP 信息。
155fact_caching = memory
156
157
158# retry files
159#retry_files_enabled = False
160#retry_files_save_path = ~/.ansible-retry
161
162[privilege_escalation]
163#become=True
164#become_method=sudo
165#become_user=root
166#become_ask_pass=False
167
168[paramiko_connection]
169
170# 取消注释这行会导致 paramiko 连接插件不记录新主机
遇到 # 个键。 提高新主机添加的性能。 设置工作独立于
# 上面的主机密钥检查设置。
173#record_host_keys=False
174
# 默认情况下,Ansible 为在 sudo 下执行的命令请求一个伪终端。 取消注释这个
# 禁用此行为。
177#pty=False
178
179[ssh_connection]
180
# 要使用的 ssh 参数
# 离开 ControlPersist 会导致性能不佳,所以使用
# paramiko 在旧平台上而不是删除它
#ssh_args = -o ControlMaster=auto -o ControlPersist=60s

# 用于 ControlPath 套接字的路径。这默认为
# "%(directory)s/ansible-ssh-%%h-%%p-%%r", 但是在某些系统上
# 很长的主机名或很长的路径名(由长用户名或
# 深度嵌套的主目录)这可能会超过字符限制
# 文件套接字名称(大多数平台为 108 个字符)。在这种情况下,你
# 不妨缩短下面的字符串。
#
# 例子:
# control_path = %(目录)s/%%h-%%r
#control_path = %(目录)s/ansible-ssh-%%h-%%p-%%r

# 启用流水线减少了 SSH 操作所需的数量
# 在远程服务器上执行一个模块。这可能会导致显着
# 启用时性能提升,但是当使用“sudo:”时,你必须
# 首先在 /etc/sudoers 中禁用 'requiretty'
#
# 默认情况下,禁用此选项以保持与
# 具有 requiretty 的 sudoers 配置(许多发行版的默认配置)。
205#pipelining = False
206
# 如果为真,如果连接类型是 ssh,则使 ansible 使用 scp
# (默认是 sftp)
209#scp_if_ssh = True
210
211[accelerate]
212accelerate_port = 5099
213accelerate_timeout = 30
214accelerate_connect_timeout = 5.0
215
# 守护进程超时以分钟为单位。 这个时间是测量的
# 从最后一个活动到加速守护进程。
218accelerate_daemon_timeout = 30
219
# 如果设置为yes,则Accelerator_multi_key 将允许多个
# 私钥上传到它,虽然每个用户都必须
# 可以通过 SSH 访问系统以添加新密钥。 默认
# 没有”。
224#accelerate_multi_key = yes
225
226[selinux]
# 在处理安全上下文时需要特殊处理的文件系统
# 复制现有上下文或使用用户默认值的默认行为
# 需要更改为使用文件系统相关上下文。
230#special_context_filesystems=nfs,vboxsf,fuse



yg9538 2022年7月22日 22:48 258 收藏文档