Apache Web Server Configuration On AWS EC2 Instance With Ansible with sudo power
In this article we configure apache web server httpd on AWS EC2 instance with ansible.
Task Description -
?? Launch an AWS instance with the help of ansible.
?? Retrieve the public IP which is allocated to the launched instance.
?? With the help of the retrieved Public IP configure the web server in the launched instance.
Before starting task Lets something know about Ansible & AWS -
INTRODUCTION TO ANSIBLE -
*Ansible is tool which is used for Configuration Management (CM). In Ansible we only tell to "what to do". We don't need to tell "How to do" because Ansible already knows that "How to do this task" on each type of Operating System .
*This intelligence of Ansible comes from "modules" . Modules know "How to do this operation on each OS". We don't require to tell particular OS command. Ansible don't perform any operation on OS. It is done by respective OS command. Ansible module know which command is required to run on OS to do this.
INTRODUCTION TO AWS -
****AWS is a cloud which is provided by Amazon. Amazon Elastic Compute Cloud (Amazon EC2 ) is a part of Amazon.com's cloud-computing platform, Amazon Web Services, that allows users to rent virtual computers on which to run their own computer applications. AWS EC2 service provisions resources like RAM , HardDisk . CPU etc.
Step - 1
?? Launch an AWS instance with the help of ansible. &
?? Retrieve the public IP which is allocated to the launched instance.
To launch ec2 instance I will use general user "controller" .
(A) Give this user to root power for all commands - (To make simple it because ansible use more commands to gathering facts)
To check This has root command power or not run this command "ansible localhost -m setup"
(B) Create a playbook (In my case ec2.yml)to create AWS EC2 instance -
In Ansible we can use ec2 module to launch aws ec2 instance, to know more about ec2 module visit this link -
***Make sure your security group allow ssh (22) and http(80) , https(443) ports .
***hello.pem is key-pair for aws ec2 instance.
In this playbook I am retrieving IP address of aws ec2 instance and copying in inventory file "/home/controller/host.txt".
To know more about ansible playbook visit this article -
Here pass.yml is a ansible vault file which has aws access key and secret key. access_key variable contains access key and secret_key variable contains secret key
To know more about ansible vault visit this article -
(C) Launch AWS instance -
ansible configuration file -
To know more about general user with ansible (sudo power) visit this article -
Run command "ansible-playbook --vault-id aws@prompt ec2.yml"
Inventory file -
Step - 2
?? With the help of the retrieved Public IP configure the web server in the launched instance.
(A) Create Another playbook (In my case httpd.yml) to configure AWS EC2 instance for web server -
I have a home.html file . I am copying this file to instance -
(B) Run httpd.yml playbook -
To check our web server is configured or not-
Now our Task is successfully done.
Thank you