Wednesday, July 13, 2022

Install and Configure Apache

 Install and Configure Apache on one of our clients

root@dcex1510ctrl001:~# cat ansible/playbooks/apacheInstallAndConfigure.yaml
- name: Ansible playbook to install and configure apache2 and restart the service 
  hosts: client01
  tasks:
  - name: Install Apache
    apt:
      name: apache2
      state: present

  - name: Configure apache
    shell: echo "My First Web Page via Ansible" > /var/www/html/index.html
    args:
      executable: /bin/bash
    notify:
      - Reload Apache
  handlers:
   - name: Reload Apache
     service:
       name: apache2
       state: reloaded


ansible-playbook -i ansible/hosts/hosts.ini ansible/playbooks/apacheInstallAndConfigure.yaml


The usage of the handler is to restart the service. if we will restart the same service several time , we can use handlers one time at the end of the playbook to restart the service only one time

No comments:

Post a Comment

Install Vault on ubuntu 20

 Today I will install vault on ubuntu 20 to use it as a part of my Ansible learning journey  Add GPG key curl -fsSL https://apt.releases.has...