Part 6 – Manage Apache & Services

This lab shows how to install the Apache on my centos servers

Example Playbook (webserver-install.yml)

sudo vi webserver-install.yml 

What this playbook does

  • Installs Apache on CentOS
---
- hosts: centos
  become: true

  vars_files:
  - ../group_vars/webserver.yml


  tasks:
    - name: Install Apache package (only where allowed)
      tags: apache
      package:
        name: "{{ apache_package }}"
        state: present
      when: apache_install | default(false)

    - name: Start Apache service (only where allowed)
      tags: apache,start
      service:
        name: "{{ apache_package }}"
        state: started
        enabled: yes
      when: apache_install | default(false)

See all tags in the playbook

ansible-playbook webserver-install.yml --list-tags

Do a dry run

ansible-playbook webserver-install.yml --check

So by Running --tags kubectl it checks what the installs is going to be

Dry‑run AWS CLI only

ansible-playbook remote-download-installer.yml --tags awscli  --check

So by Running --tags apache it checks what the installs is going to be

Install Apache CLI only

Run a check to see if httpd is installed.

ansible centos -m shell -a "systemctl status httpd --no-pager"
(Visited 6 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.