# # simple playbook to see updates and uptimes per. host and OS info # --- # Note that as of 2025-08-04 ansible_pkg_mgr is DNF for all hosts, so # we don't split this and thus. do both Fed/RH at once... - name: Check for updates hosts: distro_RedHat:distro_CentOS:distro_Fedora:!ocp*:!worker* user: root become: false tasks: # We do this explicitly because ansible will cache facts, but we want # to make sure we have the latest uptime etc. - name: Gather the latest uptime and OS ansible.builtin.setup: gather_subset: "!all,min,hardware" tags: updates # This should be in our facts, but I don't see it. Newer ansible? - name: Gather boot-id, if we can ansible.builtin.slurp: src=/proc/sys/kernel/random/boot_id register: boot_id_data ignore_errors: yes tags: updates - name: Decode the real boot-id, or use a default ansible.builtin.set_fact: boot_id: "{{ (boot_id_data.content | b64decode).strip() | default('?') }}" tags: updates # # We use the command module here because the real module can't expire # - name: Make dnf recheck for new metadata from repos ansible.builtin.command: dnf clean expire-cache tags: - expire - updates - name: Check for updates (dnf) dnf: list=updates register: pkgoutput tags: updates # Dump all our information into a file - name: Generate the Upgrade+uptime report ansible.builtin.lineinfile: regexp: '^{{inventory_hostname}} ' line: "{{inventory_hostname}} {{pkgoutput.results|length}} {{ansible_uptime_seconds}} {{ansible_date_time['date']}} {{ansible_distribution}} {{ansible_distribution_version}} {{ansible_machine_id}} {{boot_id}}" path: /var/log/ansible-list-updates-uptime.txt create: yes delegate_to: localhost tags: updates - name: Create a daily backup of the updates+uptime file. hosts: localhost tasks: - name: Sort and copy the file ansible.builtin.command: cmd: sort /var/log/ansible-list-updates-uptime.txt -o /var/log/ansible-list-updates-uptime.txt.{{ now(utc=true, fmt='%Y-%m-%d') }} tags: backup - name: Copy the sorted file back over, so it's pretty ansible.builtin.copy: src: /var/log/ansible-list-updates-uptime.txt.{{ now(utc=true, fmt='%Y-%m-%d') }} dest: /var/log/ansible-list-updates-uptime.txt tags: backup