gpt4 book ai didi

ssh - 使用 ansible 执行 ssh-add 会引发错误

转载 作者:行者123 更新时间:2023-12-04 12:06:33 25 4
gpt4 key购买 nike

我正在尝试使用 Ansible 为 ssh 连接创建基础设施。

- name: Copy ssh key to each server
copy: src=static_folder_key dest=/home/ec2-user/.ssh/ mode=0600

- name: Enable ssh Agent
shell: eval $(ssh-agent -s)

- name: Adding ssh key for static forlder project
shell: ssh-add /home/ec2-user/.ssh/static_folder_key
sudo: True

我创建了一个新的 ssh key 并复制到我的服务器。然后我执行代理,稍后我添加新 key 以允许连接。但是当我执行 ansible 时,我收到了这个错误。
TASK: [git | Adding ssh key for static forlder project] *********************** 
failed: [admin_vehicles] => {"changed": true, "cmd": "ssh-add /home/ec2-user/.ssh/static_folder_key", "delta": "0:00:00.004346", "end": "2015-08-12 15:05:00.878208", "rc": 2, "start": "2015-08-12 15:05:00.873862", "warnings": []}
stderr: Could not open a connection to your authentication agent.
failed: [leads_messages] => {"changed": true, "cmd": "ssh-add /home/ec2-user/.ssh/static_folder_key", "delta": "0:00:00.004508", "end": "2015-08-12 15:05:01.286031", "rc": 2, "start": "2015-08-12 15:05:01.281523", "warnings": []}
stderr: Could not open a connection to your authentication agent.

FATAL: all hosts have already failed -- aborting

如果我手动执行此操作,则一切正常。
ssh-add /home/ec2-user/.ssh/static_folder_key 
Identity added: /home/ec2-user/.ssh/static_folder_key (/home/ec2-user/.ssh/static_folder_key)

那么有什么提示吗?也许我在我的剧本任务中遗漏了一些东西?

最佳答案

对此的解决方案是调用 eval "$(ssh-agent)"之前ssh-add .最初我尝试了两个 Ansible 任务,但它以同样的方式失败,因为它们是原子的,无法保持状态。我最终得到的最终解决方案是在单个任务中调用这两个命令,如下所示:

  - name: Evaluating the authentication agent & adding the key...
shell: |
eval "$(ssh-agent)"
ssh-add ~/.ssh/id_rsa_svn_ssh

关于ssh - 使用 ansible 执行 ssh-add 会引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31969546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com