在我的 ansible 配置文件中,我添加了一些非默认值:
log_path=./ansible_log.txt
# (boolean) Normally ``ansible-playbook`` will print a header for each task that is run. These headers will contain the name: field from the task if you specified one. If you didn't then ``ansible-playbook`` uses the task's action to help you tell which task is presently running. Sometimes you run many of the same action and so you want more information about the task to differentiate it from others of the same action. If you set this variable to True in the config then ``ansible-playbook`` will also include the task's arguments in the header.
# This setting defaults to False because there is a chance that you have sensitive values in your parameters and you do not want those to be printed.
# If you set this to True you should be sure that you have secured your environment's stdout (no one can shoulder surf your screen and you aren't saving stdout to an insecure file) or made sure that all of your playbooks explicitly added the ``no_log: True`` parameter to tasks which have sensitive values See How do I keep secret data in my playbook? for more information.
display_args_to_stdout=True
# (boolean) Set this to "False" if you want to avoid host key checking by the underlying tools Ansible uses to connect to the host
host_key_checking=False
# (string) Set the main callback used to display Ansible output. You can only have one at a time.
# You can have many other callbacks, but just one can be in charge of stdout.
# See :ref:`callback_plugins` for a list of available options.
;stdout_callback=default
callbacks_enabled=ansible.posix.profile_tasks, ansible.posix.timer
当我ansible --version
在与执行 ansible playbook 的目录相同的目录中运行时,我得到:
ansible [核心 2.15.3]
配置文件 = /home/my_name/repos/some_repo/dev/ansible.cfg
当我使用cat /home/my_name/repos/some_repo/dev/ansible.cfg
查看配置文件的内容时,我可以验证配置是否具有上述内容。
因此,ansible--version
报告预期的 ansible.cfg 文件,该文件包含预期的设置,但这些设置似乎被忽略,我没有看到回调值的额外输出,也没有生成日志记录。
如何确保 ansible.cfg 值不被忽略?
如果这就是您忘记标头的整个配置文件
[defaults]
。ansible-config
命令可以帮助您检查您的配置。一般情况下,ansible 按以下顺序读取配置: env 变量: ANSIBLE_CONFIG 路径:
例如,如果您在当前使用的目录中运行任何命令,则检查 ansible 将使用哪个文件
ansible-config view
。它将显示将使用的文件的内容。或检查您可以使用的所有设置配置
ansible-config dump
并检查为您设置的内容。例子:
我添加的内容与我在文件底部的问题中发布的内容完全相同。变量应该位于正确的 ini 括号中,例如 [defaults]。
将其添加到正确的括号中而不是添加到文件底部后,它就起作用了。