NicoleB
NicoleB

Reputation: 55

Ansible-Failed to connect to the host via ssh

I am trying to provison an EC2 instance and to install a LAMP server on it using Ansible from localhost. I have successfully provisioned the instance, but I was not able to install apache,php and mysql due to this error "Failed to connect to the host via ssh.".

OS: El Capitan 10.11.6

Ansible: 2.0.2.0

Here is the playbook: `---

- 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

The content of the ansible.cfg file:

[defaults]
private_key_file=/Users/nico/.ssh/xxxxx.pem

The inventory:

lamp     ansible_ssh_host=<EC2 IP> ansible_user=ubuntu

The command used for running the playbook:

ansible-playbook  -i inventory  ec2_up.yml -e project_name="lamp_server"  -vvvv 

Output:

 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
}

I have read a lot of threads regarding this error, but nothing helped me. :(

Upvotes: 2

Views: 1677

Answers (1)

NicoleB
NicoleB

Reputation: 55

ansible-playbook -i inventory ec2_up.yml -e project_name="lamp_server" -vvvv -c paramiko

Upvotes: 1

Related Questions