【问题标题】:How to use multiple private keys in one inventory of Ansible如何在一个 Ansible 清单中使用多个私钥
【发布时间】:2016-02-01 14:16:06
【问题描述】:

我有一个类似的清单:

# Create an OSEv3 group that contains the masters and nodes groups
[OSEv3:children]
masters
nodes

# Set variables common for all OSEv3 hosts
[OSEv3:vars]
# SSH user, this user should allow ssh based auth without requiring a password
ansible_ssh_user=centos

# If ansible_ssh_user is not root, ansible_sudo must be set to true
ansible_sudo=true

product_type=openshift
deployment_type=enterprise

# uncomment the following to enable htpasswd authentication; defaults to DenyAllPasswordIdentityProvider
#openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/openshift/openshift-passwd'}]

# host group for masters
[masters]
master.example.com

# host group for nodes, includes region info
[nodes]
master.example.com openshift_node_labels="{'region': 'infra', 'zone': 'default'}"
node1.example.com openshift_node_labels="{'region': 'primary', 'zone': 'east'}"
node2.example.com openshift_node_labels="{'region': 'primary', 'zone': 'west'}"

现在我需要密钥来使主机可以访问 ansible。 我有 2 把钥匙。一个给我的主人,一个给我的节点。如何更改此脚本以告知 ansible 它必须使用哪个键?

脚本将在我的主人身上执行。我的主人包含/root/.ssh/中的2个键

目前我现在只能在/etc/ansible/ansible.cfg 中使用private_key_file,但这只能为 Ansible 配置一个标准密钥。

【问题讨论】:

    标签: ssh key ansible


    【解决方案1】:

    您可以在库存中定义behavioral parameters。在每个主机后面或在单独的 group:vars 部分中。由于您有多个节点共享相同的密钥,因此后者更有意义:

    [masters:vars]
    ansible_ssh_private_key_file=1.pem
    
    [nodes:vars]
    ansible_ssh_private_key_file=2.pem
    

    【讨论】:

    • 我得到:错误:/etc/ansible/hosts:30:分配给组的变量必须采用键=值形式
    • Aaand 你有key=value 格式的吗?您可以将您的更新添加到上面的问题中吗?
    • nvm 现在可以使用:我必须定义:ansible_ssh_private_key_file=....pem(您可以在答案中编辑它)
    • 我无法关注你。我的答案中有 key=value 表示法。
    • 该死的,是的。我错了对不起。以为这是您的 .pem 的长名称。我太快了,对不起,谢谢你的正确答案。
    猜你喜欢
    • 2014-04-18
    • 2016-10-25
    • 1970-01-01
    • 2014-11-29
    • 2020-02-27
    • 1970-01-01
    • 1970-01-01
    • 2023-02-03
    • 1970-01-01
    相关资源
    最近更新 更多