Execution
Date 11 Sep 2025 12:56:57 +0100
Duration 00:00:23.59
Controller ssh-gw-4.layershift.com
User root
Versions
Ansible 2.16.11
ara 1.7.3 / 1.7.3
Python 3.10.10
Summary
44 Hosts
3 Tasks
44 Results
2 Plays
1 Files
0 Records

File: /home/ssh-gateway/ansible/kuly/find_snowflakes_repos.yaml

---
- name: Check for 3rd-party enabled repositories on AlmaLinux 8
  hosts: all
  become: true
  vars:
    allowed_repos:
      - baseos
      - appstream
      - extras
      - powertools
      - devel
      - ha
      - resilientstorage
      - sap
      - sap-hana
      - epel
      - epel-modular
    report_dir: "/tmp/ansible_snowflake_reports_{{ ansible_play_uuid }}"

  tasks:
    - name: Ensure local report directory exists
      ansible.builtin.file:
        path: "{{ report_dir }}"
        state: directory
        mode: '0755'
      delegate_to: localhost
      run_once: true

    - name: Get list of enabled repos
      ansible.builtin.command: dnf repolist --enabled --quiet
      register: repolist
      changed_when: false

    - name: Parse enabled repo IDs
      ansible.builtin.set_fact:
        enabled_repos: >-
          {{
            repolist.stdout_lines[1:]
            | map('regex_replace', '^([^ ]+).*', '\\1')
            | list
            | map('trim')
            | reject('eq', '')
            | list
          }}

    - name: Identify 3rd-party repos
      ansible.builtin.set_fact:
        thirdparty_repos: "{{ enabled_repos | difference(allowed_repos) }}"

    - name: Write host report to local CSV file
      ansible.builtin.copy:
        content: "{{ inventory_hostname }},{{ thirdparty_repos | join(';') if thirdparty_repos | length > 0 else 'None' }}\n"
        dest: "{{ report_dir }}/{{ inventory_hostname }}.csv"
        mode: '0644'
      delegate_to: localhost


- name: Generate Tabular and CSV Report (Local Summary)
  hosts: localhost
  gather_facts: false
  vars:
    report_dir: "/tmp/ansible_snowflake_reports_{{ ansible_play_uuid }}"
    csv_file: "{{ report_dir }}/snowflake_report.csv"

  tasks:
    - name: Aggregate all host reports into single CSV
      ansible.builtin.shell: |
        echo "host,thirdparty_repos" > "{{ csv_file }}"
        cat "{{ report_dir }}"/*.csv >> "{{ csv_file }}"
      args:
        executable: /bin/bash

    - name: Read CSV data for tabular display
      ansible.builtin.read_csv:
        path: "{{ csv_file }}"
        key: host
      register: csv_data

    - name: Display tabular report
      ansible.builtin.debug:
        msg: |
          {% set max_host_len = (csv_data.list | map(attribute='host') | map('length') | max) + 2 %}
          {% set header_host = 'HOST' | center(max_host_len) %}
          {% set header_repos = 'THIRD-PARTY REPOS' %}
          {{ '=' * (max_host_len + 40) }}
          {{ header_host }} | {{ header_repos }}
          {{ '-' * (max_host_len + 40) }}
          {% for row in csv_data.list %}
          {{ row.host | center(max_host_len) }} | {{ row.thirdparty_repos }}
          {% endfor %}
          {{ '=' * (max_host_len + 40) }}

    - name: Show CSV file location
      ansible.builtin.debug:
        msg: "✅ Full CSV report saved to: {{ csv_file }}"

    - name: (Optional) Cleanup report dir after
      ansible.builtin.file:
        path: "{{ report_dir }}"
        state: absent
      # Uncomment below if you want to auto-cleanup
      # when: false