amazon web services - Ansible AWS: Unable to connect to EC2 instance -


what want achieve

i want create ec2 instance lamp stack installed using 1 ansible playbook.

problem

the instance creation works fine, , can modify in ec2 console, problem appears when trying access instance example install apache or create keys.

this error:

fatal: [35.154.26.86]: unreachable! => { "changed": false, "msg": "[errno none] unable connect port 22 on or 35.154.26.86", "unreachable": true }

error screenshot

code

this playbook:

--- - name: power ec2 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 ec2 variables       debug: var=ec2      - name: add instance public ips 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 here, don't know do.     - name: create 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      # rest installing lamp 

information:

1- hosts file default.

2- used command run playbook:

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

3- launch-wizard-1 has ssh.

4- mykeypair public key imported device console(don't know if ok)

5- big newbie

ansible requires python installed on vm work.

here required code:

  - name: upload ssh keypair ec2     hosts: localhost     connection: local     gather_facts: false     vars:       keypair_name: key_name       key_material: "{{ lookup('file', 'keyfile') }}"       region: "{{ region }}"       tasks:       - name: ssh keypair ec2         ec2_key:           aws_access_key: "xxxxxxxxxxxxxxxxxxx"           aws_secret_key: "xxxxxxxxxxxxxxxxxxx"           region: "{{ region }}"           name: "{{ keypair_name }}"           key_material: "{{ key_material }}"           state: present     - name: power ec2 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 instance 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 instance public ips host group         add_host: hostname={{ item.public_ip }} groups=ec2hosts         with_items: "{{ ec2.instances }}" 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -