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

Ansible 2.4.2.0中能否通过命令行覆盖inventory的ansible_ssh_private_key_file?

在Ansible 2.4.2.0中无法通过--private-key覆盖inventory的SSH密钥设置

没错,在Ansible 2.4.2.0版本里,你没办法用--private-key命令行选项覆盖inventory文件中定义的ansible_ssh_private_key_file参数,这个问题已经在对应的GitHub Issue(标题:Command-line flags (variable weight) not respected (bug or a feature?))里被反馈确认过了。

举个例子,假设你的inventory配置是这样的:

[group1]
instance1 ansible_host=host1 ansible_user=user1 ansible_ssh_private_key_file=~/.ssh/user1host1-id_rsa

当你执行这条命令时:

ansible-playbook playbook1.yml --private-key=some_other-id_rsa

Ansible依然会优先使用inventory里指定的~/.ssh/user1host1-id_rsa密钥,而不是你命令行传入的some_other-id_rsa。这是因为当时版本的Ansible变量优先级规则中,inventory层面定义的连接变量优先级高于命令行传递的--private-key选项。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 06:41:51