Adding existing playbooks and test files
This commit is contained in:
parent
5afc4b4049
commit
2b49288da1
94
README.md
94
README.md
@ -1,92 +1,22 @@
|
||||
# updates-dashboard-ansible
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.infolegale.net/infrastructure/updates-dashboard-ansible.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.infolegale.net/infrastructure/updates-dashboard-ansible/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||
|
||||
## Test and Deploy
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||
|
||||
***
|
||||
|
||||
# Editing this README
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
Playbooks ansible utilisés pour récupérer les informations à intégrer dans l'updates-dashboard.
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
Les playbooks vont récuperer et afficher les informations suivantes sur les machines :
|
||||
* Main.yml : hostname, distribution, version, update disponible, uptime.
|
||||
* Packages.yml : hostname, paquet, version.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
La liste des paquets à vérifier se trouve dans le playbook packages.yml.
|
||||
Un callback particulier est utilisé pour afficher seulement les informations voulues pour construire le csv.
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
* Ajouter callback_plugins=./hooks/ à ansible.cfg
|
||||
```
|
||||
export ANSIBLE_STDOUT_CALLBACK="update_dashboard"
|
||||
DATE=$(date '+%Y-%m-%d')
|
||||
ansible-playbook -i hosts-tst playbooks/main.yml > $DATE.csv
|
||||
```
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
|
||||
6
ansible.cfg
Normal file
6
ansible.cfg
Normal file
@ -0,0 +1,6 @@
|
||||
[defaults]
|
||||
interpreter_python = auto
|
||||
callback_plugins = ./hooks/
|
||||
fact_caching = jsonfile
|
||||
fact_caching_connection = ~/.cache/ansible/
|
||||
deprecation_warnings = False
|
||||
BIN
hooks/__pycache__/update_dashboard.cpython-38.pyc
Normal file
BIN
hooks/__pycache__/update_dashboard.cpython-38.pyc
Normal file
Binary file not shown.
23
hooks/update_dashboard.py
Normal file
23
hooks/update_dashboard.py
Normal file
@ -0,0 +1,23 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
||||
class CallbackModule(CallbackBase):
|
||||
|
||||
CALLBACK_VERSION = 2.0
|
||||
CALLBACK_TYPE = 'stdout'
|
||||
CALLBACK_NAME = 'update_dashboard'
|
||||
|
||||
def v2_runner_on_ok(self, result):
|
||||
if result._task.action == 'debug':
|
||||
ansible_msg = result._result.get('msg', None)
|
||||
if ansible_msg:
|
||||
print(ansible_msg)
|
||||
|
||||
def v2_runner_on_unreachable(self, result):
|
||||
print("%s;UNREACHABLE" % result._host.get_name())
|
||||
|
||||
def v2_runner_on_failed(self, result, ignore_errors=False):
|
||||
print("%s;FAILED" % result._host.get_name())
|
||||
44
hosts-tst
Normal file
44
hosts-tst
Normal file
@ -0,0 +1,44 @@
|
||||
##########
|
||||
# VARS
|
||||
##########
|
||||
[all:vars]
|
||||
env='tst'
|
||||
symfony_env="recette"
|
||||
vmpass='$6$oIJS8mHoKPJVXZIR$fQVPI7.M9/3wD6O.8JS5iYIL6v0tx3BfmiHKIeb/h88yL9R9GYsGJnePK9UEoBZ2F8AfZhwHGRvV3iv9CGChV.'
|
||||
relayhost='maildump.infolegale.net'
|
||||
scriptsToSupervise=[['borg-backup.sh','129600']]
|
||||
graylogapp="graylog-log001-stg.infolegale.net:12201"
|
||||
cmk_server_ip="10.12.251.1"
|
||||
|
||||
[mysql]
|
||||
tlearning-db003-tst.infolegale.net
|
||||
vlearning-db001-tst.infolegale.net
|
||||
app-db001-tst.infolegale.net
|
||||
consults-db001-tst.infolegale.net
|
||||
vador-db001-tst.infolegale.net
|
||||
transdb-db001-tst.infolegale.net
|
||||
mysql8-db001-tst.infolegale.net
|
||||
|
||||
[mongo]
|
||||
mongo-db001-tst.infolegale.net
|
||||
|
||||
[mgr]
|
||||
orchestrator-mgr001-tst.infolegale.net
|
||||
|
||||
[redis]
|
||||
redis-db001-tst.infolegale.net
|
||||
redis5-db001-tst.infolegale.net
|
||||
|
||||
[docker]
|
||||
docker-hpv001-tst.infolegale.net
|
||||
docker-hpv002-tst.infolegale.net
|
||||
docker-hpv003-tst.infolegale.net
|
||||
docker-hpv004-tst.infolegale.net
|
||||
docker-hpv005-tst.infolegale.net
|
||||
docker-hpv006-tst.infolegale.net
|
||||
|
||||
[proxysql]
|
||||
proxysql-db001-tst.infolegale.net
|
||||
|
||||
[rundeck]
|
||||
rundeck-sch001-tst.infolegale.net
|
||||
55
playbooks/auto-updates-result.yml
Normal file
55
playbooks/auto-updates-result.yml
Normal 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
|
||||
47
playbooks/main.yml
Normal file
47
playbooks/main.yml
Normal file
@ -0,0 +1,47 @@
|
||||
---
|
||||
|
||||
###
|
||||
# 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"
|
||||
68
playbooks/packages.yml
Normal file
68
playbooks/packages.yml
Normal file
@ -0,0 +1,68 @@
|
||||
---
|
||||
|
||||
- hosts: all
|
||||
|
||||
strategy: free
|
||||
|
||||
vars:
|
||||
- packages :
|
||||
- apt
|
||||
- apache2
|
||||
- bash
|
||||
- check-mk-agent
|
||||
- elasticsearch
|
||||
- libc-bin
|
||||
- make
|
||||
- mysql-server
|
||||
- nginx
|
||||
- openssh-server
|
||||
- php5
|
||||
- php7.0
|
||||
- php7.1
|
||||
- php7.2
|
||||
- php7.4
|
||||
- postfix
|
||||
- proxysql
|
||||
- redis
|
||||
- redis-server
|
||||
- sphinxsearch
|
||||
- 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 }}"
|
||||
10
playbooks/packages_include.yml
Normal file
10
playbooks/packages_include.yml
Normal 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 != ""
|
||||
Loading…
x
Reference in New Issue
Block a user