首页 > 解决方案 > 即使在添加到 ssh-add 之后,Ansible 也总是要求输入 ssh 关键字

问题描述

ssh-add在初始化后添加了我的密钥$(ssh-agent)

原始 ssh 命令完全可以正常工作,只需密钥且无需密码 ssh -i key.pem ubuntu@someip

到目前为止一切顺利,问题是如果我运行 ansible playbook 在同一个终端运行,它要求输入密钥密码!并且不允许自动化它

TASK [deploy-all : Copy something to remote host] *******************
Wednesday 30 June 2021  18:04:56 +0200 (0:00:00.609)       0:00:03.063 ******** 
Enter passphrase for key 'key.pem': 

它甚至多次询问密码......在同一个剧本执行期间。(我有一些任务委托给 localhost delegate_to:“{{ delegate_build_to_host }}”,所以当上下文切换到远程主机时似乎再次询问密码)

库存文件:

[webserver]
dockerall ansible_host=some.host.ip.xy ansible_user=ubuntu ansible_ssh_private_key_file=key.pem

Playbook 只是使用唯一的主机组网络服务器

---

- hosts: webserver
  become: true
  gather_facts: false
  environment:
    CI: "true"
  vars:
    working_user: root

  - { role: deploy, tags: 'deploy' }

部署角色的第一项任务非常简单,我被要求输入密码: roles/deploy/tasks/main.yaml

# identation is wrong but doesn't matter just copied for example
  copy:
    src: "{{ role_path }}/files/docker/"
    dest: "{{ dc_path }}"
    mode: preserve

// more tasks here some delegated to localhost
- name: "create tmp build directory in build host to contain all sort of tmp files that can be deleted after execution"
  delegate_to: "localhost"
  file:
    path: "{{ tmp_build_path }}"
    recurse: yes
    state: directory

// again after this comment, copy tasks for remote host

关键文件权限:

stat -c "%a %n" key.pem

600 key.pem

标签: sshansible

解决方案


推荐阅读