Ansible-Playbook Explained for New Users

Ansible-Playbook Explained for New Users

Learn to write an Ansible playbook for apache2 installation and app deployment on AWS.

Ansible is an excellent automation tool that simplifies deploying applications and managing configurations across multiple servers. In this blog, we’ll walk through writing a playbook to install Apache2 and deploy a static app on AWS.

Following are the steps to achieve this:

  1. Set up password-less authentication between the control node and managed nodes to ensure seamless communication using SSH keys.

  2. Create an inventory file to define the target servers (managed nodes) that Ansible will interact with.

  3. Write an Ansible playbook to automate the tasks of installing Apache2, deploying the static app, and starting the Apache2 service.

  4. Create a static HTML file (index.html) that will serve as the app to be deployed.

  5. Execute the Playbook: Run the following command to execute the Ansible playbook and perform the tasks defined within it:

     ansible-playbook -i inventory.ini apache-playbook.yml
    

    private_ip_ctrl

  6. Verify Apache2 Installation: After running the playbook, SSH into the managed node to check if Apache2 is running:

     ssh <private_ip_address_of_managed_node>
     sudo ps -ef | grep apache2
     sudo systemctl status apache2
    

  7. Allow Traffic on Port 80: Update the inbound rules of your AWS instance's security group to allow HTTP traffic on port 80. This ensures that the deployed static app is accessible over the internet.

  8. View the Results: Open a web browser and enter the public IP address of the managed node. You should see your static app displayed, confirming the successful deployment.