--- ### # This playbook aims to retrieve a 'state' of our servers, ie for each server: # - what is the OS, in which version (we focus on debian / ubuntu and centos) # - for centos and debian-based distribs, how many available updates are there? # # Call it with the callback made for it: callback_plugin=update_dashboard in ansible.cfg # or after running export ANSIBLE_STDOUT_CALLBACK="update_dashboard" # also: callback_plugins = ./hooks/callback:/usr/share/ansible_plugins/callback_plugins ### - hosts: "all" strategy: free tasks: # ## All hosts ## # - name: get uptime shell: uptime=$(uptime | grep -o "[0-9][0-9]* days" | awk '{ print $1 }'); if [ "$uptime" ]; then echo $uptime; else echo 0; fi register: uptime changed_when: False tags: - skip_ansible_lint # ## Debian / RedHat hosts ## # # get auto-updates script status - include: auto-updates-result.yml when: "'auto_updates' in group_names and ((ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 6) or (ansible_os_family == 'Debian' and ansible_distribution_major_version|int >= 8))" - name: set status if not in auto-updates set_fact: auto_updates_status=NA when: "'auto_updates' not in group_names or (ansible_os_family == 'RedHat' and ansible_distribution_major_version|int < 6) or (ansible_os_family == 'Debian' and ansible_distribution_major_version|int < 8)" ## Debian # get number of updates and debug - name: (debian) update apt cache if older than 1 day apt: update_cache=yes cache_valid_time=86400 register: update_cache_result ignore_errors: yes - name: (debian) check available updates on debian systems shell: apt-get --dry-run dist-upgrade | grep '^Inst' | wc -l warn=no register: available_updates when: update_cache_result is succeeded - name: (Debian) output debug: msg="{{ inventory_hostname }};{{ ansible_distribution }};{{ ansible_distribution_major_version }};{{ available_updates.stdout | default('') }};{{ uptime.stdout }};{{ auto_updates_status | default('UNK')}}" when: ansible_distribution == "Debian" - name: (Ubuntu) output debug: msg="{{ inventory_hostname }};{{ ansible_distribution }};{{ ansible_distribution_version }};{{ available_updates.stdout | default('') }};{{ uptime.stdout }};{{ auto_updates_status | default('UNK')}}" when: ansible_distribution == "Ubuntu"