48 lines
1.7 KiB
YAML
48 lines
1.7 KiB
YAML
---
|
|
|
|
###
|
|
# 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
|
|
|
|
# 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 }}"
|
|
when: ansible_distribution == "Debian"
|
|
|
|
- name: (Ubuntu) output
|
|
debug: msg="{{ inventory_hostname }};{{ ansible_distribution }};{{ ansible_distribution_version }};{{ available_updates.stdout | default('') }};{{ uptime.stdout }}"
|
|
when: ansible_distribution == "Ubuntu"
|