Initial commit with sources

This commit is contained in:
Sebastien Laithier
2022-08-17 10:12:40 +02:00
parent 216dee6714
commit d6e8f370e9
99 changed files with 26675 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
---
# This is to get the auto-updates script status from log file
# It returns in stat_log:
# - OUT if file older than 40 days
# - ERR if recent but ERROR in file
# - OK if recent and OK in file
# nothing else (main playbook manage it as an UNK status)
- name: check if there is an auto-updates log file
stat: path="{{ log_dir }}/scripts/auto-updates.log"
register: stat_log
- name: set error status
set_fact: auto_updates_status=ERR
when: not stat_log.stat.exists
- name: check if log file is less than 1 month old
shell: "find {{ log_dir }}/scripts/ -name 'auto-updates.log' -mtime -40 | wc -l"
register: date_log
when: stat_log.stat.exists
- name: set outdated status
set_fact: auto_updates_status=OUT
when: date_log.stdout is defined and date_log.stdout != "1"
- name: check ok status if recent log file
command: "grep OK {{ log_dir }}/scripts/auto-updates.log"
register: ok_log
failed_when: False
when: date_log.stdout is defined and date_log.stdout == "1"
- name: set ok status
set_fact: auto_updates_status=OK
when: ok_log.rc is defined and ok_log.rc != 1
- name: check error if old log file
command: "grep ERROR {{ log_dir }}/scripts/auto-updates.log"
register: error_log
failed_when: false
when: date_log.stdout is defined and date_log.stdout == "1"
- name: set error status
set_fact: auto_updates_status=ERR
when: error_log.rc is defined and error_log.rc != 1
- name: check running status if recent log file
command: "grep RUNNING {{ log_dir }}/scripts/auto-updates.log"
register: running_log
failed_when: false
when: stat_log.stat.exists
- name: set error status
set_fact: auto_updates_status=ERR
when: running_log.rc is defined and running_log.rc != 1

66
ansible/main.yml Normal file
View File

@@ -0,0 +1,66 @@
---
###
# 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"

73
ansible/packages.yml Normal file
View File

@@ -0,0 +1,73 @@
---
- hosts: all
strategy: free
vars:
- packages :
- apt
- apache2
- bash
- dnsmasq
- exim
- httpd
- libc-bin
- mailx
- make
- mariadb-server
- memcached
- mysql-server
- nagios
- nginx
- nrpe
- openssh-server
- php5
- php7.0
- php7.1
- php7.2
- php7.4
- phpmyadmin
- postfix
- redis
- redis-server
- sudo
- systemd
tasks:
# Loop on package list to get versions
- name: Check packages lists
include: packages_include.yml package="{{ item }}"
with_items:
- "{{ packages }}"
# Get the RUNNING kernel
## Debian
- when: ansible_distribution == "Debian" and ansible_distribution_major_version|int >= 7
block:
- name: (Debian) get kernel version
shell: uname -v | awk '{ print $4 }'
register: kernel_version_debian
changed_when: false
- name: (Debian) Kernel output
debug: msg="{{ inventory_hostname }};kernel;{{ kernel_version_debian.stdout }}"
## Ubuntu
- when: ansible_distribution == "Ubuntu" and ansible_distribution_major_version|int >= 16
block:
- name: (Ubuntu) get kernel version
shell: uname -r
register: kernel_version_ubuntu
changed_when: false
- name: (ubuntu) Kernel output
debug: msg="{{ inventory_hostname }};kernel;{{ kernel_version_ubuntu.stdout }}"

View File

@@ -0,0 +1,10 @@
---
- name: check package version
shell: dpkg -l | awk '$2=="{{ package }}" { print $3 }'
register: package_version_debian
changed_when: false
- name: output
debug: msg="{{ inventory_hostname }};{{ package }};{{ package_version_debian.stdout }}"
when: package_version_debian.stdout != ""