Apache Web Server Configuration On AWS EC2 Instance With Ansible with sudo power

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)

No alt text provided for this image

To check This has root command power or not run this command "ansible localhost -m setup"

No alt text provided for this image

(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 -

No alt text provided for this image

***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

No alt text provided for this image

To know more about ansible vault visit this article -

(C) Launch AWS instance -

ansible configuration file -

No alt text provided for this image

To know more about general user with ansible (sudo power) visit this article -

Run command "ansible-playbook --vault-id aws@prompt ec2.yml"

No alt text provided for this image
No alt text provided for this image

Inventory file -

No alt text provided for this image

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 -

No alt text provided for this image

I have a home.html file . I am copying this file to instance -

No alt text provided for this image

(B) Run httpd.yml playbook -

No alt text provided for this image

To check our web server is configured or not-

No alt text provided for this image

Now our Task is successfully done.

Thank you

要查看或添加评论,请登录

Govind Bhardwaj的更多文章

社区洞察

其他会员也浏览了