在M1芯片Mac上安装Ansible启动报错求助
在M1芯片Mac上启动Ansible时出现配置错误
错误信息
执行ansible命令时触发如下错误:
➜ ~ ansible Unhandled error: Traceback (most recent call last): File "/opt/homebrew/Cellar/ansible/6.2.0/libexec/lib/python3.10/site-packages/ansible/config/manager.py", line 547, in get_config_value_and_origin value = ensure_type(value, defs[config].get('type'), origin=origin) File "/opt/homebrew/Cellar/ansible/6.2.0/libexec/lib/python3.10/site-packages/ansible/config/manager.py", line 89, in ensure_type value = int(value) ValueError: invalid literal for int() with base 10: '' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/homebrew/Cellar/ansible/6.2.0/libexec/lib/python3.10/site-packages/ansible/config/manager.py", line 619, in update_config_data value, origin = self.get_config_value_and_origin(config, configfile) File "/opt/homebrew/Cellar/ansible/6.2.0/libexec/lib/python3.10/site-packages/ansible/config/manager.py", line 554, in get_config_value_and_origin raise AnsibleOptionsError('Invalid type for configuration option %s: %s' % ansible.errors.AnsibleOptionsError: Invalid type for configuration option setting: DEFAULT_GATHER_TIMEOUT : invalid literal for int() with base 10: '' ERROR: Invalid settings supplied for DEFAULT_GATHER_TIMEOUT: Invalid type for configuration option setting: DEFAULT_GATHER_TIMEOUT : invalid literal for int() with base 10: '' . Invalid type for configuration option setting: DEFAULT_GATHER_TIMEOUT : invalid literal for int() with base 10: ''
已尝试操作
- 分别使用Homebrew和pip两种方式安装Ansible,均出现相同错误
环境信息
Python依赖版本(pip freeze输出)
➜ ~ pip freeze ansible==6.2.0 ansible-core==2.13.2 cffi==1.15.1 cryptography==37.0.4 Jinja2==3.1.2 MarkupSafe==2.1.1 packaging==21.3 pycparser==2.21 pyparsing==3.0.9 PyYAML==6.0 resolvelib==0.8.1 six @ file:///AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/python3/python3-110/six-1.15.0-py2.py3-none-any.whl
macOS版本信息(sw_vers输出)
➜ ~ sw_vers ProductName: macOS ProductVersion: 12.5 BuildVersion: 21G72
解决方案
问题根源
错误指向DEFAULT_GATHER_TIMEOUT配置项,该参数要求整数值,但当前配置为空字符串,导致类型转换失败。
修复步骤
定位Ansible配置文件:
- 检查以下路径的配置文件:
- 系统级:
/etc/ansible/ansible.cfg - 用户级:
~/.ansible.cfg - 项目级:当前工作目录下的
ansible.cfg
- 系统级:
- 检查以下路径的配置文件:
修正配置值:
打开找到的配置文件,在[defaults]小节下找到DEFAULT_GATHER_TIMEOUT(或gather_timeout),将其设置为有效整数值,例如默认的10秒:[defaults] gather_timeout = 10若配置项不存在,直接添加上述内容即可。
验证修复:
重新执行ansible命令,确认错误已消除。
内容的提问来源于stack exchange,提问作者FrysGreatGreatGreatNephew
相关产品推荐
相关产品推荐

