我正在尝试提供EC2实例并使用来自localhost的Ansible在其上安装LAMP服务器。我已成功配置该实例,但由于此错误“无法通过ssh连接到主机”,我无法安装apache,php和mysql。
操作系统:El Capitan 10.11.6
Ansible:2.0.2.0
这是剧本:`---
- hosts: localhost
connection: local
gather_facts: no
vars_files:
- "vars/{{ project_name }}.yml"
- "vars/vpc_info.yml"
tasks:
- name: Provision
local_action:
module: ec2
region: "xxxxxx"
vpc_subnet_id: "xxxxxx"
assign_public_ip: yes
key_name: "xxxxxxx"
instance_type: "t2.nano"
image: "xxxxxxxx"
wait: yes
instance_tags:
Name: "LAMP"
class: "test"
environment: "dev"
project: "{{ project_name }}"
az: a
exact_count: 1
count_tag:
Name: "LAMP"
monitoring: yes
register: ec2a
- hosts: lamp
roles:
- lamp_server
ansible.cfg文件的内容:
[defaults]
private_key_file=/Users/nico/.ssh/xxxxx.pem
库存:
lamp ansible_ssh_host=<EC2 IP> ansible_user=ubuntu
用于运行剧本的命令:
ansible-playbook -i inventory ec2_up.yml -e project_name="lamp_server" -vvvv
输出:
ESTABLISH SSH CONNECTION FOR USER: ubuntu
<xxxxxxxxxx> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/Users/nico/.ssh/xxxxxxx.pem"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ubuntu -o ConnectTimeout=10 -o ControlPath=/Users/nico/.ansible/cp/ansible-ssh-%h-%p-%r xxxxxxx '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1475186461.08-93383010782630 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1475186461.08-93383010782630 `" )'"'"''
52.28.251.117 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh.",
"unreachable": true
}
我已经阅读了很多有关此错误的主题,但没有任何帮助。 :(
答案 0 :(得分:0)
ansible-playbook -i inventory ec2_up.yml -e project_name =&#34; lamp_server&#34; -vvvv -c paramiko