如何在 Ansible 的一个清单中使用多个私钥
How to use multiple private keys in one inventory of Ansible
我有一个 ansible 清单,如下所示:
# 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 配置一个标准密钥。
您可以在清单中定义 behavioral parameters。在每个主机后面或在单独的 group:vars
部分中。由于您有多个共享相同密钥的节点,后者更有意义:
[masters:vars]
ansible_ssh_private_key_file=1.pem
[nodes:vars]
ansible_ssh_private_key_file=2.pem
我有一个 ansible 清单,如下所示:
# 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/
目前我只在 /etc/ansible/ansible.cfg
中 private_key_file
但只能为 Ansible 配置一个标准密钥。
您可以在清单中定义 behavioral parameters。在每个主机后面或在单独的 group:vars
部分中。由于您有多个共享相同密钥的节点,后者更有意义:
[masters:vars]
ansible_ssh_private_key_file=1.pem
[nodes:vars]
ansible_ssh_private_key_file=2.pem