Deploy Web Server On AWS Through Ansible

ansible-vault create --vault-id Abhi@prompt secret.yml
- hosts: "localhost"
vars_files:
- secret.yml
tasks:
- name: "ANSIBLE_AWS_EC2"
ec2:
key_name: "Abhinav"
instance_type: "t2.micro"
image: "ami-0ebc1ac48dfd14136"
wait: yes
count: 1
instance_tags:
Name: EC2_BY_ANSIBLE
vpc_subnet_id: "subnet-3e0b1456"
assign_public_ip: yes
region: "ap-south-1"
state: present
group_id: "sg-452b0f3c"
aws_access_key: "{{access_Key}}"
aws_secret_key: "{{secret_Key}}"
register: Abhi
- debug:
var: Abhi.instances[0].private_ip
register: IP_Var
- debug:
var: IP_Var["Abhi.instances[0].private_ip"]
ansible-palybook --vault-id Abhi@prompt Aws.yml

👉🏼Step-4

Now, we will configure HTTPD server in the Ec2 instance. For this we will write one playbook.

- hosts: all
tasks:
- name: httpd ec2
command: "sudo yum install httpd -y"
- name: start service
service:
name: "httpd"
state: started
enabled: yes
- name: copy files
copy:
src: "/etc/ansible/Task_1/abhinav.html"
dest: "/var/www/html/"
ansible-playbook web.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