我想在Ansible的幫助下創建和配置Amazon EC2計算機。 現在,我得到以下錯誤:Ansible Amazon EC2。密鑰對不存在
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Instance creation failed => InvalidKeyPair.NotFound: The key pair '~/.keys/EC2-Kibi-Enterprise-Deployment.pem' does not exist"}
但.PEM項是否存在:
$ ls -lh ~/.keys/EC2-Kibi-Enterprise-Deployment.pem
-r-------- 1 sergey sergey 1.7K Apr 6 09:56 /home/sergey/.keys/EC2-Kibi-Enterprise-Deployment.pem
,它是在歐盟(愛爾蘭)區創建。
這裏是我的劇本:
--
- name: Setup servers on Amazon EC2 machines
hosts: localhost
gather_facts: no
tasks:
- include_vars: group_vars/all/ec2_vars.yml
### Create Amazon EC2 instances
- name: Amazon EC2 | Create instances
ec2:
count: "{{ count }}"
key_name: "{{ key }}"
region: "{{ region }}"
zone: "{{ zone }}"
group: "{{ group }}"
instance_type: "{{ machine }}"
image: "{{ image }}"
wait: true
wait_timeout: 500
#vpc_subnet_id: "{{ subnet }}"
#assign_public_ip: yes
register: ec2
- name: Amazon EC2 | Wait for SSH to come up
wait_for:
host: "{{ item.public_ip }}"
port: 22
delay: 10
timeout: 60
state: started
with_items: "{{ ec2.instances }}"
- name: Amazon EC2 | Add hosts to the kibi_servers in-memory inventory group
add_host: hostname={{ item.public_ip }} groupname=kibi_servers
with_items: "{{ ec2.instances }}"
### END
### Provision roles
- name: Amazon EC2 | Provision new instances
hosts: kibi_servers
become: yes
roles:
- common
- java
- elasticsearch
- logstash
- nginx
- kibi
- supervisor
### END
而且我var文件:
count: 2
region: eu-west-1
zone: eu-west-1a
group: default
image: ami-d1ec01a6
machine: t2.medium
subnet: subnet-3a2aa952
key: ~/.keys/EC2-Kibi-Enterprise-Deployment.pem
什麼是錯在這裏.pem文件?
我是否需要在本地創建SSH密鑰對並在亞馬遜控制檯中導入公鑰?這是關鍵嗎? – trex
您需要將公鑰(不是私有部分)上傳到AWS。您可以通過控制檯執行此操作,也可以按照示例通過Ansible執行此操作。 – ydaetskcoR
似乎'ec2_keypair'模塊不存在。但有[ec2_key](http://docs.ansible.com/ansible/ec2_key_module.html)模塊。我使用它,並且在var文件中還指出了'key_name:〜/ .ssh/EC2-Kibi-Enterprise'。現在我有以下錯誤:'失敗:[localhost] =>(item = ssh-rsa AA ...「,」msg「:」必須指定region或ec2_url「}' – trex