Configure Web server and Load balancer using Ansible on ec2 instance

- hosts: localhost
tasks:
- ec2:
region: us-east-1
image: ami-0be2609ba883822ec
instance_type: t2.micro
vpc_subnet_id: subnet-b64fced0
group_id: sg-d51499e1
key_name: N.verginea_key_pair
instance_tags:
Name: "WebServer"
count_tag:
Name: "WebServer"
exact_count: 2
aws_access_key: '******************'
aws_secret_key: '***********************'
register: ec2
- hosts: localhost
tasks:
- ec2:
region: us-east-1
image: ami-0be2609ba883822ec
instance_type: t2.micro
vpc_subnet_id: subnet-b64fced0
group_id: sg-d51499e1
key_name: N.verginea_key_pair
instance_tags:
Name: "LoadBalancer"
count_tag:
Name: "LoadBalancer"
exact_count: 1
aws_access_key: '*******************'
aws_secret_key: '**************************************'
register: ec2
- hosts: tag_Name_WebServer
tasks:
- name: "install apache "
package:
name: "httpd"
state: present
- name: "install php"
package:
name: "php"
state: present
- copy:
src: "index.php"
dest: "/var/www/html"
- template:
src: "dhiru.conf"
dest: "/etc/httpd/conf.d/conf/dhiru.conf"
- service:
name: "httpd"
state: restarted
enabled: yes
- hosts: tag_Name_LoadBalancer
tasks:
- name: "install haproxy"
package:
name: "haproxy"
state: present
- template:
src: "haproxy.cfg.j2"
dest: "/etc/haproxy/haproxy.cfg"
- service:
name: "haproxy"
state: restarted
ansible-playbook lb_web_config_ec2.yml

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store