【问题标题】:how can add my private key to a target host through ansible如何通过ansible将我的私钥添加到目标主机
【发布时间】:2017-06-07 20:41:27
【问题描述】:

我有一个来自 /home/renz/.shh/id_rsa.pub 的 shh 密钥。我想通过 ansible 将它添加到 /root/.shh/authorized_keys 中的目标主机。我试过了,但没有用。

---
- hosts: snapzio
  tasks:
    - name: Set authorized key took from file
      authorized_key:
        user: master
        state: present
        key: "{{ lookup('file', '/home/renz/.ssh/id_rsa.pub') }}"
        path: /root/.ssh/authorized_keys

因为首先,我无法与主机通信,因为我的密钥不在授权密钥中。如果我想与许多主机交流,我认为这个想法是有意义的。而不是手动复制和粘贴密钥。

【问题讨论】:

标签: vagrant ansible devops


【解决方案1】:

正如其他人所提到的,如果您在 Ansible 中使用的帐户没有安装 SSH 密钥,您将不得不回退到使用密码身份验证。假设 InstallMyKey.yml 是你的剧本,你可以这样运行:

ansible-playbook InstallMyKey.yml --ask-become-pass 

您需要将remote_user: root 行添加到您的YML 中hosts:tasks: 行之间,然后输入root 密码。

假设 playbook 成功并且 root SSH 设置中的所有其他内容都正确,那么您下一次运行 playbook 应该使用 renz ssh 密钥并且无需密码即可继续。

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 2020-12-24
    • 2017-02-01
    • 1970-01-01
    • 2022-06-22
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    相关资源
    最近更新 更多