gpt4 book ai didi

amazon-ec2 - Ansible 亚马逊 EC2。 key 对不存在

转载 作者:行者123 更新时间:2023-12-02 23:16:29 25 4
gpt4 key购买 nike

我想在 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 key 存在:

$ 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 文件有什么问题?

最佳答案

ec2 modulekey 参数正在查找已上传到 AWS 的 key 对名称,而不是本地 key 。

如果您想让 Ansible 上传公钥,您可以使用 ec2_key module .

所以你的剧本将如下所示:

--
- name: Setup servers on Amazon EC2 machines
hosts: localhost
gather_facts: no

tasks:
- include_vars: group_vars/all/ec2_vars.yml

### Create Amazon EC2 key pair
- name: Amazon EC2 | Create Key Pair
ec2_key:
name: "{{ key_name }}"
region: "{{ region }}"
key_material: "{{ item }}"
with_file: /path/to/public_key.id_rsa.pub

### Create Amazon EC2 instances
- name: Amazon EC2 | Create instances
ec2:
count: "{{ count }}"
key_name: "{{ key_name }}"
...

关于amazon-ec2 - Ansible 亚马逊 EC2。 key 对不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36447118/

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