Skip to content

Latest commit

 

History

History
110 lines (84 loc) · 1.9 KB

Ex-9.md

File metadata and controls

110 lines (84 loc) · 1.9 KB

Installation of Ansible and Deploy Playbook to web server

Procedure to install Ansible in Mac OS

  1. Install Ansible
brew install ansible
  1. Check Ansible version
ansible --version

Procedure to install in Ubuntu

  1. Update the apt package index
sudo apt update
sudo apt upgrade
  1. Install Ansible
sudo apt install ansible
  1. Check Ansible version
ansible --version
  1. Create a directory for Ansible
mkdir ansible
cd ansible
  1. Create a file named playbook.yml using the following command
touch playbook.yml
  1. Copy the following code and paste it in the file playbook.yml
- name: Install and configure web server
  hosts: localhost
  connection: local
  become: true
  tasks:
    - name: Install Apache web server
      apt:
        name: apache2
        state: present
    - name: Create index.html file
      template:
        src: index.html.j2
        dest: /var/www/html/index.html
    - name: Set ownership and permissions on index.html
      file:
        path: /var/www/html/index.html
        owner: www-data
        group: www-data
        mode: "0644"
  handlers:
    - name: restart apache2
      service:
        name: apache2
        state: restarted
  1. Create a file named index.html.j2 using the following command
touch index.html.j2
  1. Copy the following code and paste it in the file index.html.j2
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ansible</title>
</head>
<body>
    <h1>Hello World!</h1>
</body>
</html>
  1. Run the playbook using the following command
ansible-playbook playbook.yml
  1. Open the browser and type localhost Link in the address bar and hit enter

  2. You will see the following output