# Day 57 : Understanding Configuration Management with Ansible

* **Task-01: Installing Ansible on AWS EC2 (Master Node)**  
      
    1\. Create an EC2 instance (Master)
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687494012777/b3274ad9-6dc1-4b9c-9c41-1b7bf54a981f.png align="center")
    
    To install Ansible, follow these steps:
    
    * SSH into your EC2 instance.
        
    * Run the following commands one by one:
        
    
    ```bash
    sudo apt-add-repository ppa:ansible/ansible 
    sudo apt update 
    sudo apt install ansible
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687494267309/a27336c8-70d8-4c41-b993-28c321b356df.png align="center")
    
    1. Checking the Hosts file
        
        To verify the contents of the Hosts file, use the following command:
        
    
    ```bash
    cat /etc/ansible/hosts
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687494587524/b6542bd8-b5da-49d7-896b-406683fe8338.png align="center")
    
    1. Checking the inventory
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687495317888/ad09e370-01a8-4398-9e86-ddfc5bc8d712.png align="center")
    

**Task-02: Setting up additional EC2 instances (Nodes)**

To set up additional EC2 instances, follow these steps:

Launch two more EC2 instances similar to the previous one.

Select master instance , Go to action then image and templates and then click on Launch more like this.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687495441300/c2574b2c-d6db-4604-a53c-94a2fd4a79c9.png align="center")

Choose same private keys and launch 2 instances

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687495574419/3b6d0d02-ac1b-4e1f-b872-1af2615da947.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687495678136/2f5c347b-1fde-434a-a266-816a5b966122.png align="center")

1. Copy the private key of the new instances to the master server where Ansible is set up.
    

Go to the `.ssh` folder and create an `ansible_key` file. Paste the private key that you used to create the instances.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687495987460/fed10c4e-631b-4298-a771-eecf1a0b791e.png align="center")

Create an inventory file using the `vim` command or any other text editor.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687496624148/7c950ded-c8e1-4a06-8960-a12cd36071f3.png align="center")

Enter the public IP addresses of both instances (servers) in the inventory file.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687496668507/f6595b21-6a50-49b0-845b-f2d8847fae99.png align="center")

To verify the inventory, use the following command:

```bash
ansible-inventory -i inventory --list
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687496731092/8d67dbf3-030c-459e-8b3d-f5c17f54cc23.png align="center")

1. Try a ping command using Ansible to the nodes. Run the following command:
    

To ping run following command.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687497102505/18f6fbf4-3b2e-4e63-bf85-c79673407250.png align="center")

Make sure to change the permissions of your private key. The output should display a successful ping to the nodes.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687497185094/264ee6ba-59bf-48b6-b42f-6aa83f9a1cd8.png align="center")

and your output will be like following.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687497228472/9b5dbd5b-894b-412b-bd18-90a6b867abcf.png align="center")

That was all for today. See you another day with another challenge.
