# Day #59: Ansible Project

# ask-01

* create 3 EC2 instances . make sure all three are created with same key pair
    
* Install Ansible in host server
    
* copy the private key from local to Host server (Ansible\_host) at (/home/ubuntu/.ssh)
    
* access the inventory file using sudo vim /etc/ansible/hosts
    
* Create a playbook to install Nginx
    
* deploy a sample webpage using the ansible playbook
    

* Create 3 EC2 instances and make sure all three are created with the same key pair.
    
    1. Three servers are created that include Ansible master and node servers.
        
* Install Ansible on the host server
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686639344043/84778644-2c9c-48c5-8515-c08ec738ec41.png align="center")
    
    1. Create the ansible repository in the master server.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683662151978/32093ef2-98dd-4b11-af2b-6538e4fb02c7.png?auto=compress,format&format=webp align="left")
        
    2. Install Ansible through apt in the master server.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683662192655/eed26373-05e7-4c7e-a672-1252010c81ee.png?auto=compress,format&format=webp align="left")
        
* copy the private key from local to the Host server (Ansible\_host) at (/home/ubuntu/.ssh)
    
    1. Copy the private key that you have created while creating the server.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683662288226/74b0cb35-938f-4338-be95-ffe67174dd69.png?auto=compress,format&format=webp align="left")
        
    2. Create an ansible key file and store the above private key.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683662434425/eefd328d-8d78-4ba2-943c-b5879490cbbc.png?auto=compress,format&format=webp align="left")
        
    3. Provide access permission for the key file.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683662485886/862304fd-a751-4d56-88eb-006a23d9846a.png?auto=compress,format&format=webp align="left")
        
* access the inventory file using sudo vim /etc/ansible/hosts
    
    1. Create the inventory file in the master server to link the node servers to the master server.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683662677175/a5d0ed0e-bde5-4cd4-af83-22c258e2cdc2.png?auto=compress,format&format=webp align="left")
        
* Create a playbook to install Nginx
    
    1. Create a playbook to install, start and enable the Nginx in both the node servers.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663017539/41d8396c-2fbc-432f-8725-7752aaad3b11.png?auto=compress,format&format=webp align="left")
        
    2. Execute the ansible-playbook yaml file to perform the task.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663074873/195012f6-1ec6-4790-8432-699c5e23fd4b.png?auto=compress,format&format=webp align="left")
        
* deploy a sample webpage using the ansible-playbook
    
    1. Create a webpage index.html file in the master server.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663157776/9c535139-7fda-459d-b3dc-226cbb995483.png?auto=compress,format&format=webp align="left")
        
    2. Modify the ansible-playbook to transfer the index.html file to the Nginx location.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663190513/dff9123c-0ade-4ced-9260-cca571be1a60.png?auto=compress,format&format=webp align="left")
        
    3. Execute the ansible-playbook to execute the webpage.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663237225/1f499c37-e4b5-4a0c-ae2f-778fbcde1993.png?auto=compress,format&format=webp align="left")
        
    4. Login to the first node server to check the webpage.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663265944/1fc7f21d-3710-4af7-9d7f-1f499202c39a.png?auto=compress,format&format=webp align="left")
        
    5. Login to the second node server to check the webpage.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683663353426/c6eb5db3-b416-453a-995e-356949a3c933.png?auto=compress,format&format=webp align="left")
