2017-01-30 116 views
-1

我試圖運行Ansible以下劇本:「無法通過ssh連接到主機」錯誤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 

但是,劇本運行失敗。有人可以幫我解決我做錯的事嗎?

+0

SSH安裝是否正確?日誌表明你的公鑰沒有工作。 – andyhky

+0

@andyhky是的。 'ssh-add the pem file worked :)。 Pl將其添加爲答案。會接受! – Dawny33

回答

1

答案必須在: 權限被拒絕(publickey)。 您已經通過了主機密鑰檢查 - 您的問題與身份驗證有關。 您是否打算使用基於密鑰的身份驗證?如果是這樣,

ssh <host> -l <ansible_user> 

爲你工作,還是它產生密碼提示?

您是否嘗試使用密碼驗證?如果是這樣,它看起來像你的節點不允許它。

編輯: 將-vvvv添加到您的playbook可啓用SSH調試。

1

SSH安裝是否正確?日誌表明你的公鑰沒有工作

相關問題