not able to connect webserver deployed frm "ansible & aws course"

I think this might be issue with port opening or something, I am not able to see the index.html file i have deplyed into my EC2 instance.
Getting the beow error. Please suggest

Network Error (tcp_error)

A communication error occurred: "Connection refused"

The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time.

For assistance, contact your network support team.

Code


--- #Creating a WebServer
- hosts: aws
remote_user: ec2-user
connection: ssh
become: yes
gather_facts: yes
tasks:
- name: Installing Apache WebServer and update server
yum: pkg={{ item }} state=latest
with_items:
- httpd
- wget
notify:
- CopyContent
- restarthttpd
- sitetest
handlers:
- name: CopyContent
copy: src=index.html dest=/var/www/html/index.html owner=root group=root mode=0655 backup=yes
- name: restarthttpd
service: name=httpd state=restarted
- name: sitetest
shell: /usr/bin/wget http://localhost
register: webs
- debug: var=webs
- hosts: localhost
remote_user: test
connection: ssh
become: yes
gather_facts: yes
vars_files:
- awskeys.yml
tasks:
- name: Deploying WebServer and backup snapshots
ec2_snapshot:
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
region: ap-south-1
instance_id: i-094a6a68a8a80a7ab
device_name: /dev/xvda
description: Creation of backup
wait: yes
register: snap
- debug: var=snap
- name: createnewami
ec2_ami:
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
region: ap-south-1
instance_id: i-094a6a68a8a80a7ab
wait: yes
name: anisble_ami
tags:
Name: My Ansible AMI Template
Service: WebServer template
register: amiboss
- debug: var=amiboss

Regards,
Sami Shaik.
  • post-author-pic
    Terrence C
    09-17-2018

    Hi Sami!


    Yes, the error you indicate above is generally because the connection cannot be made. Now, it certainly could be because Apache is not listening on the server in question, but I assume since you didn't report an error with the playbook that installs and starts the service, that is not an issue.

    Your security group will have to allow either your IP or all IP addresses to connect to your EC2 instance over port 80 for this to succeed.

Looking For Team Training?

Learn More