You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ansible 2.10版本ansible-config缺失init选项,无法生成默认配置

解决Ansible 2.10.8生成带完整注释的默认配置文件问题

问题描述

我尝试用init选项为Ansible 2.10.8生成默认配置,但发现该选项不存在,不知道怎么生成文档里提到的包含所有注释的配置文件。

相关命令输出如下:

ansible --version 输出

ansible --version
ansible 2.10.8
  config file = /home/filip/DevOps/Ansible/ansible.cfg
  configured module search path = ['/home/filip/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0]

ansible-config 命令帮助输出

sudo ansible-config
usage: ansible-config [-h] [--version] [-v] {list,dump,view} ...
ansible-config: error: the following arguments are required: action
 
usage: ansible-config [-h] [--version] [-v] {list,dump,view} ...

View ansible configuration.

positional arguments:
  {list,dump,view}
    list            Print all config options
    dump            Dump configuration
    view            View configuration file

options:
  --version         show program's version number, config file location, configured module search path, module location, executable location and exit
  -h, --help        show this help message and exit
  -v, --verbose     verbose mode (-vvv for more, -vvvv to enable connection debugging)

解决方案

Ansible 2.10.x版本确实没有ansible-config init命令,这个命令是在Ansible 2.11及以上版本才新增的。要生成带完整注释的默认配置文件,可通过以下两种方法实现:

  • 复制系统自带的示例配置文件
    多数发行版的Ansible会自带示例配置文件,路径通常为/usr/share/doc/ansible/examples/ansible.cfg(不同发行版可能略有差异)。直接复制该文件到你的工作目录即可:

    cp /usr/share/doc/ansible/examples/ansible.cfg ./ansible.cfg
    

    这个文件包含所有可用配置项的详细注释说明。

  • 用ansible-config list生成带注释的配置
    使用ansible-config list命令可以输出所有配置项的完整信息(含默认值和注释),将输出重定向到文件就能得到标准格式的配置文件:

    ansible-config list --format ini > ansible.cfg
    

内容的提问来源于stack exchange,提问作者h00jraq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 00:56:03