【问题标题】:"Failed to connect to the host via ssh" error Ansible“无法通过 ssh 连接到主机”错误 Ansible
【发布时间】:2023-03-20 15:00:01
【问题描述】:

我正在尝试在 Ansible 上运行以下剧本:

- hosts: localhost
  connection: local
  remote_user: test
  gather_facts: no

  vars_files:
    - files/aws_creds.yml
    - files/info.yml

  tasks:
    - name: Basic provisioning of EC2 instance
      ec2:
        assign_public_ip: no
        aws_access_key: "{{ aws_id }}"
        aws_secret_key: "{{ aws_key }}"
        region: "{{ aws_region }}"
        image: "{{ standard_ami }}"
        instance_type: "{{ free_instance }}"
        key_name: "{{ ssh_keyname }}"
        count: 3
        state: present
        group_id: "{{ secgroup_id }}"
        wait: no
        #delete_on_termination: yes
        instance_tags:
          Name: Dawny33Template
      register: ec2

    - name: Add new instance to host group
      add_host:
        hostname: "{{ item.public_ip }}"
        groupname: launched
      with_items: "{{ ec2.instances }}"

## Here lies the SSH code
    - name: Wait for SSH to come up
      wait_for:
        host: "{{ item.public_ip }}"
        port: 22
        delay: 60
        timeout: 320
        state: started
      with_items: "{{ ec2.instances }}"


- name: Configure instance(s)
  hosts: launched
  become: True
  gather_facts: True
  #roles:
  #  - my_awesome_role
  #  - my_awesome_test

- name: Terminate instances
  hosts: localhost
  connection: local
  tasks:
    - name: Terminate instances that were previously launched
      ec2:
        state: 'absent'
        instance_ids: '{{ ec2.instance_ids }}'

我收到以下错误:

TASK [setup] *******************************************************************
fatal: [52.32.183.176]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '52.32.183.176' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey).\r\n", "unreachable": true}
fatal: [52.34.255.16]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '52.34.255.16' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey).\r\n", "unreachable": true}
fatal: [52.34.253.51]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '52.34.253.51' (ECDSA) to the list of known hosts.\r\nPermission denied (publickey).\r\n", "unreachable": true}

我的 ansible.cfg 文件已经包含以下内容:

[defaults]
host_key_checking = False

然而,剧本运行失败了。有人可以帮我解决我做错的事情吗?

【问题讨论】:

  • SSH 设置是否正确?日志表明您的公钥不起作用。
  • @andyhky 是的。 ssh-addpem 文件有效:)。请添加它作为答案。会接受!

标签: ssh amazon-ec2 ansible


【解决方案1】:

答案必须在于: 权限被拒绝(公钥)。 您通过了主机密钥检查-您的问题在于身份验证。 您是否打算使用基于密钥的身份验证?如果是这样,是吗

ssh <host> -l <ansible_user>

为您工作,还是会产生密码提示?

您是否尝试使用密码验证?如果是这样,您的节点似乎不允许这样做。

编辑: 将 -vvvv 添加到您的 playbook 可以启用 SSH 调试。

【讨论】:

  • -vvvv 帮我做了,结果 known_hosts 文件搞砸了。
【解决方案2】:

SSH 设置是否正确?日志表明您的公钥无效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-08
    • 2017-02-08
    • 2018-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    相关资源
    最近更新 更多