2017-07-28 3 views
1

verbinden Was ich erreichen möchte

Ich möchte eine EC2-Instanz mit LAMP-Stack erstellen installiert mit einem ansible Textbuch.ansible AWS: Kann nicht EC2-Instanz

Problem

Die Instanz Schöpfung funktioniert gut, und ich kann es in der EC2-Konsole ändern, aber das Problem wird angezeigt, wenn die Instanz zuzugreifen versuchen, zum Beispiel Apache installieren oder Schlüssel erstellen.

Dies ist der Fehler:

fatal: [35.154.26.86]: UNREACHABLE! => { "changed": false, "msg": "[Errno None] Unable to connect to port 22 on or 35.154.26.86", "unreachable": true }

Error Screenshot

-Code

Das ist mein Textbuch ist:

--- 
- name: Power up an ec2 with LAMP stack installed 
    hosts: localhost 
    become: true 
    become_user: root 
    gather_facts: False 
    vars: 
    keypair: myKeyPair 
    security_group: launch-wizard-1 
    instance_type: t2.micro 
    image: ami-47205e28 
    region: x-x-x 
    tasks: 
    - name: Adding Python-pip 
     apt: name=python-pip state=latest 

    - name: Install Boto Library 
     pip: name=boto 

    - name: Launch instance (Amazon Linux) 
     ec2: 
     key_name: "{{ keypair }}" 
     group: "{{ security_group }}" 
     instance_type: "{{ instance_type }}" 
     image: "{{ image }}" 
     wait: true 
     region: "{{ region }}" 
     aws_access_key: "xxxxxxxxxxxxxxxxxxx" 
     aws_secret_key: "Xxxxxxxxxxxxxxxxxxx" 
     register: ec2 

    - name: Print all ec2 variables 
     debug: var=ec2 

    - name: Add all instance public IPs to host group 
     add_host: hostname={{ item.public_ip }} groups=ec2hosts 
     with_items: "{{ ec2.instances }}" 


- hosts: ec2hosts 
    remote_user: ec2-user 
    become: true 
    gather_facts: false 
    tasks: 
#I need help here, don't know what to do. 
    - name: Create an EC2 key 
     ec2_key: 
     name: "privateKey" 
     region: "x-x-x" 
     register: ec2_key 

    - name: Save private key 
     copy: content="{{ ec2_key.private_key }}" dest="./privateKey.pem" mode=0600 
     when: ec2_key.changed 

    # The Rest is installing LAMP 

Information:

1- Meine Hosts-Datei ist Standard.

2- verwenden ich diesen Befehl, um das Textbuch auszuführen:

sudo ansible-playbook lamp.yml -vvv -c paramiko

3- Anfahrzeit-Wizard-1 SSH hat.

4- myKeyPair ist ein öffentlicher Schlüssel von meinem Gerät an die Konsole importiert (weiß nicht, ob das ok ist)

5- ich ein großer Neuling

+0

Warum Sie nicht folgen Beispiel aus dem [docs] (http://docs.ansible.com/ansible/latest/ec2_module.html)? Beachten Sie die Aufgabe _Wait für SSH, um nach oben zu gehen. Und das nächste Problem, auf das Sie stoßen werden, ist die Ausführung von 'ec2_key' auf dem entfernten Host. –

Antwort

0

ansible erfordert Python auf VM installiert bin Arbeit.

Hier ist Ihr erforderlicher Code:

- name: upload an ssh keypair to ec2 
    hosts: localhost 
    connection: local 
    gather_facts: False 
    vars: 
     keypair_name: Key_name 
     key_material: "{{ lookup('file', 'keyfile') }}" 
     region: "{{ region }}" 


    tasks: 
     - name: ssh keypair for ec2 
     ec2_key: 
      aws_access_key: "xxxxxxxxxxxxxxxxxxx" 
      aws_secret_key: "Xxxxxxxxxxxxxxxxxxx" 
      region: "{{ region }}" 
      name: "{{ keypair_name }}" 
      key_material: "{{ key_material }}" 
      state: present 


    - name: Power up an ec2 with LAMP stack installed 
    hosts: localhost 
    become: true 
    become_user: root 
    gather_facts: False 
    vars: 
     keypair: myKeyPair 
     security_group: launch-wizard-1 
     instance_type: t2.micro 
     image: ami-47205e28 
     region: x-x-x 
     my_user_data: | # install Python: Ansible needs Python pre-installed on the instance to work! 
     #!/bin/bash 
     sudo apt-get install python -y 

    tasks: 
     - name: Adding Python-pip 
     apt: name=python-pip state=latest 

     - name: Install Boto Library 
     pip: name=boto 

     - name: Launch instance (Amazon Linux) 
     ec2: 
      key_name: "{{ keypair }}" 
      group: "{{ security_group }}" 
      instance_type: "{{ instance_type }}" 
      image: "{{ image }}" 
      wait: true 
      wait_timeout: 300 
      user_data: "{{my_user_data}}" 
      region: "{{ region }}" 
      aws_access_key: "xxxxxxxxxxxxxxxxxxx" 
      aws_secret_key: "Xxxxxxxxxxxxxxxxxxx" 
     register: ec2 

     - name: Add all instance public IPs to host group 
     add_host: hostname={{ item.public_ip }} groups=ec2hosts 
     with_items: "{{ ec2.instances }}" 
Verwandte Themen