Execution
Date 27 Aug 2024 12:12:28 +0100
Duration 00:15:27.12
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.4
ara 1.7.1 / 1.7.1
Python 3.10.10
Summary
382 Hosts
14 Tasks
4625 Results
1 Plays
6 Files
0 Records

File: /home/ssh-gateway/ansible/projects/RM9703/RM9703-update-httpd.yaml

---
- name: Playbook to update httpd
  hosts: all
  roles:
    - plesk
  tasks:
    - name: Update and check
      when: "'Plesk' in plsk_out.stdout"
      block:
        - name: Verify Apache configuration
          ansible.builtin.command: apachectl configtest
          register: apachectl_result
          changed_when: false

        - name: Fail if Apache configuration is incorrect
          ansible.builtin.fail:
            msg: "Apache configuration test failed: {{ apachectl_result.stderr | default('') }} {{ apachectl_result.stdout | default('') }}"
          when: apachectl_result.rc != 0

        - name: Check if OS is CentOS
          ansible.builtin.set_fact:
            package_manager: "{{ 'yum' if ansible_facts['os_family'] == 'RedHat' and ansible_facts['distribution_major_version'] == '7' else 'dnf' }}"

        - name: Update httpd with cache rebuild CentOS
          when: package_manager == "yum"
          ansible.builtin.yum:
            name: httpd
            state: latest
            update_cache: true

        - name: Rebuild cache and update httpd alma
          when: package_manager == "dnf"
          ansible.builtin.dnf:
            name: httpd
            state: latest
            update_cache: true

        - name: Add a small pause to allow apache to start
          ansible.builtin.wait_for:
            timeout: 4

        - name: Verify that httpd service is active and running
          ansible.builtin.systemd:
            name: httpd
            state: started
          register: httpd_service_status
          failed_when:
            - httpd_service_status.status.ActiveState != "active"

        - name: Notify if httpd service restarted successfully
          ansible.builtin.debug:
            msg: "The httpd service has been restarted successfully and is active."
          when: httpd_service_status.status.ActiveState == "active"