如何将我的id_rsa ssh密钥导入test-kitchen(kitchen.yml),以便可以使用它登录所有厨房管理的VM?

时间:2019-07-11 20:42:57

标签: vagrant test-kitchen

从我的kitchen.yml中,我正在使用流浪汉驱动程序,并试图导入我的id_rsa密钥,以便可以将其用于ssh进入这些主机。这是我的kitchen.yml:

x <- 1:10
y <- 5:14
p <- 0.5
plot(x, y, xlim = c(min(x) - p*diff(range(x)), max(x) + p*diff(range(x))), 
        xaxs = "i", 
        ylim = c(min(y) - p*diff(range(y)), max(y) + p*diff(range(y))), 
        yaxs = "i")

如您所见,我正在尝试许多方法来导入我的密钥。

在构建VM之后尝试使用密钥时,我只会看到以下错误:

#kitchen.yml
---
driver:
name: vagrant

# Ansible configuration
provisioner:
  name: ansible_playbook
#  ansible_cfg_path: <%= ENV['WORKSPACE'] %>/ansible.cfg
  ansible_extra_flags: <%= ENV['ANSIBLE_EXTRA_FLAGS'] %>
  roles_path: <%= ENV['WORKSPACE'] %>/roles
  playbook: <%= ENV['WORKSPACE'] %>/kubernetes.yml
  ansible_inventory: <%= ENV['WORKSPACE'] %>/inventory.yml
  hosts: kubernetes
  require_pip: true
#  requirements_path:
  ansible_verbose: true
  ansible_verbosity: 2
  ansible_diff: true
  ansible_version: latest
  require_chef_for_busser: false
  ansible_connection: ssh
  ansible_host_key_checking: false
  private_key: $HOME/.ssh/swat.pem
  additional_ssh_private_keys:
    - ~/.ssh/id_rsa

transport:
  ssh_key: ~/.ssh/id_rsa
  connection_timeout: 10
  connection_retries: 5

# Vagrant network configuration
platforms:
  - name: centos7-01
    driver_plugin: vagrant
    driver_config:
      box: centos/7
      network:
        - ['public_network', {bridge: "en0: Wi-Fi (AirPort)", ip: '192.168.0.11'}]
    ssh_key: ~/.ssh/id_rsa
  - name: centos7-02
    driver_plugin: vagrant
    driver_config:
      box: centos/7
      network:
        - ['public_network', {bridge: "en0: Wi-Fi (AirPort)", ip: '192.168.0.12'}]
  - name: centos7-03
    driver_plugin: vagrant
    driver_config:
      box: centos/7
      network:
        - ['public_network', {bridge: "en0: Wi-Fi (AirPort)", ip: '192.168.0.13'}]
  - name: centos7-04
    driver_plugin: vagrant
    driver_config:
      box: centos/7
      network:
        - ['public_network', {bridge: "en0: Wi-Fi (AirPort)", ip: '192.168.0.14'}]

# Deployment/Environment settings
suites:
  - name: version-1-0
    run_list:
    attributes:

它似乎仅在使用ssh -i ~/.ssh/id_rsa vagrant@192.168.0.11 The authenticity of host '192.168.0.11 (192.168.0.11)' can't be established. ECDSA key fingerprint is SHA256:OlCjFbGhdpm+NH9vs3AdBcCV+A7QWNSn3nG05evnBGI. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.0.11' (ECDSA) to the list of known hosts. vagrant@192.168.0.11: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 命令生成的private_key时才连接。

1 个答案:

答案 0 :(得分:0)

当您使用Kitchen旋转节点实例时,该节点会用vagrant user烘焙

  

默认情况下,Vagrant希望“无用”用户以SSH身份登录到计算机。

这允许流浪汉能够通过ssh连接到该节点。 当您为ssh连接指定密钥时,您基本上会覆盖流浪汉在建立ssh连接时提供的默认密钥。

如果要使用自己的密钥,则必须确保ssh配置(用户名,密钥文件等)与操作系统ssh服务器一致。

基本上,您可以创建自己的自定义vagrant框,但是由于您使用的是配置管理(ansible),因此我强烈建议您将vagrant ssh配置保留为它,同时利用ansible创建用户及其ssh配置。 / p>