Execution
Date 11 Mar 2026 18:35:42 +0000
Duration 00:07:40.29
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.13
ara 1.7.4 / 1.7.4
Python 3.10.10
Summary
397 Hosts
10 Tasks
3952 Results
1 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/RM10320-check-mariadb.yaml

---
- name: Check MariaDB Installation and Repo Version Consistency
  hosts: all
  gather_facts: false

  vars:
    repo_file_path: "/etc/yum.repos.d/mariadb.repo"
    package_name: "MariaDB-server"

  tasks:
    - name: Check if MariaDB-server is installed
      ansible.builtin.command:
        cmd: rpm -q --queryformat '%{VERSION}' {{ package_name }}
      register: rpm_check
      failed_when: false
      changed_when: false
      check_mode: false

    - name: Set installation facts
      ansible.builtin.set_fact:
        installed: "{{ rpm_check.rc == 0 }}"
        version: "{{ rpm_check.stdout | default('') }}"

    - name: Extract major version if installed
      ansible.builtin.set_fact:
        major: "{{ version | regex_search('^([0-9]+\\.[0-9]+)') | default('') }}"
      when: installed

    - name: Check repo file
      ansible.builtin.stat:
        path: "{{ repo_file_path }}"
      register: repo_stat

    - name: Parse repo version if file exists
      when: repo_stat.stat.exists
      block:
        - name: Read repo file
          ansible.builtin.slurp:
            src: "{{ repo_file_path }}"
          register: repo_content

        - name: Extract repo major version
          ansible.builtin.set_fact:
            repo_version: >-
              {{
                (repo_content.content | b64decode)
                | regex_search('baseurl.*?/([0-9]+\.[0-9]+)/', '\1')
                | first | default('')
              }}

    - name: Handle version mismatch (only output when there's a problem)
      ansible.builtin.debug:
        msg: "⚠️  {{ inventory_hostname }} | installed: {{ version }} ({{ major }}) | repo: {{ repo_version | default('none') }} | MISMATCH"
      when:
        - installed
        - repo_stat.stat.exists
        - repo_version is defined
        - repo_version | length > 0
        - major | length > 0
        - major != repo_version

    - name: Handle missing repo file
      ansible.builtin.debug:
        msg: "ℹ️  {{ inventory_hostname }} | installed: {{ version }} ({{ major }}) | repo file missing"
      when:
        - installed
        - not repo_stat.stat.exists

    - name: Handle missing installation
      ansible.builtin.debug:
        msg: "ℹ️  {{ inventory_hostname }} | MariaDB not installed"
      when: not installed

    - name: Handle OK installations (quiet mode - only shown if you want them)
      ansible.builtin.debug:
        msg: "✓  {{ inventory_hostname }} | installed: {{ version }} | repo: {{ repo_version }} | OK"
      when:
        - installed
        - repo_stat.stat.exists
        - repo_version is defined
        - repo_version | length > 0
        - major | length > 0
        - major == repo_version
      tags: ['verbose']