Execution
Date 11 Mar 2026 15:27:33 +0000
Duration None
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
0 Hosts
2 Tasks
0 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
  become: true
  gather_facts: true

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

  tasks:
    - name: Gather package facts
      ansible.builtin.package_facts:
        manager: "rpm"
      when: ansible_pkg_mgr in ['yum', 'dnf']

    - name: Set installation facts
      ansible.builtin.set_fact:
        installed_version: "{{ ansible_facts.packages[package_name][0].version if package_name in ansible_facts.packages else '' }}"
        is_installed: "{{ package_name in ansible_facts.packages }}"
      when: ansible_pkg_mgr in ['yum', 'dnf']

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

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

    - name: Get repo version
      when: repo.stat.exists
      block:
        - name: Read repo file
          ansible.builtin.slurp:
            src: "{{ repo_file_path }}"
          register: content
        - name: Parse repo major version
          ansible.builtin.set_fact:
            repo_major: "{{ (content.content | b64decode) | regex_search('baseurl.*?/([0-9]+\\.[0-9]+)/', '\\1') | first | default('') }}"

    - name: Check for version mismatch
      ansible.builtin.debug:
        msg: "⚠️  MISMATCH on {{ inventory_hostname }}: installed {{ installed_major }} vs repo {{ repo_major | default('missing') }}"
      when:
        - is_installed
        - installed_major | length > 0
        - repo.stat.exists
        - repo_major is defined
        - repo_major | length > 0
        - installed_major != repo_major
      changed_when:
        - is_installed
        - installed_major | length > 0
        - repo.stat.exists
        - repo_major is defined
        - repo_major | length > 0
        - installed_major != repo_major

    - name: Show OK status
      ansible.builtin.debug:
        msg: "✓ {{ inventory_hostname }}: {{ installed_version if is_installed else 'not installed' }}"
      when: not (is_installed and installed_major | length > 0 and repo.stat.exists and repo_major is defined and repo_major | length > 0 and installed_major != repo_major)