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
相关产品推荐
相关产品推荐

