Skip to content

Commit

Permalink
add dagnostic role and merge glances to it
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermeindl committed Jan 18, 2024
1 parent 2dfd526 commit 3502494
Show file tree
Hide file tree
Showing 24 changed files with 352 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: "alphanodes.setup.glances"
name: "alphanodes.setup.diagnostic"
'on':
pull_request:
push:
Expand All @@ -9,13 +9,13 @@ name: "alphanodes.setup.glances"
- 'roles/python/**'
- 'molecule/python/**'
- '.github/workflows/python.yml'
- 'roles/glances/**'
- 'molecule/glances/**'
- '.github/workflows/glances.yml'
- 'roles/diagnostic/**'
- 'molecule/diagnostic/**'
- '.github/workflows/diagnostic.yml'

defaults:
run:
working-directory: 'glances'
working-directory: 'diagnostic'

jobs:
build:
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Check out the codebase.
uses: actions/checkout@v4
with:
path: 'glances'
path: 'diagnostic'

- name: Set up Python 3.
uses: actions/setup-python@v4
Expand All @@ -49,6 +49,6 @@ jobs:
- name: Run Molecule tests.
run: |
molecule --version
molecule test -s glances
molecule test -s diagnostic
env:
MOLECULE_DISTRO: ${{ matrix.distro }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ All provided roles do not use docker as container system.
- [alphanodes.setup.git](roles/git/)
- [alphanodes.setup.git_config](roles/git_config/)
- [alphanodes.setup.gitlab](roles/gitlab/)
- [alphanodes.setup.glances](roles/glances/)
- [alphanodes.setup.diagnostic](roles/diagnostic/)
- [alphanodes.setup.goaccess](roles/goaccess/)
- [alphanodes.setup.golang](roles/golang/)
- [alphanodes.setup.hedgedoc](roles/hedgedoc/)
Expand All @@ -54,6 +54,7 @@ All provided roles do not use docker as container system.
- [alphanodes.setup.redmine](roles/redmine/)
- [alphanodes.setup.rocketchat](roles/rocketchat/)
- [alphanodes.setup.rsync](roles/rsync/)
- [alphanodes.setup.rvm](roles/rvm/)
- [alphanodes.setup.sphinx](roles/sphinx/)
- [alphanodes.setup.ssh](roles/ssh/)
- [alphanodes.setup.ssl](roles/ssl/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
force: true

roles:
- role: alphanodes.setup.glances
- role: alphanodes.setup.diagnostic
File renamed without changes.
21 changes: 21 additions & 0 deletions roles/diagnostic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ansible Role: Diagnostic tools

Setup diagnostic tools on Debian and Ubuntu servers.

## Role Variables

Available variables can be found in [defaults/main.yml](defaults/main.yml)

## Example Playbook

```yaml
- hosts: all

vars:
diagnostic_with_btop: true
diagnostic_with_glances: true
diagnostic_with_htop: true

roles:
- alphanodes.setup.diagnostic
```
23 changes: 23 additions & 0 deletions roles/diagnostic/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# defaults file for diagnostic tools

diagnostic_with_atop: false
diagnostic_with_bottom: false
# bottom is not implemented at the moment
diagnostic_with_btop: true
# make sure pip is installed for glances
diagnostic_with_glances: tfalse
diagnostic_with_htop: false
diagnostic_with_nmap: false
diagnostic_with_sysstat: false

diagnostic_packages:
- deborphan

# required a lot of packages for glances without pip (e.g. nginx)
glances_with_pip: true
glances_pip_packages:
- glances
glances_pip_venv: glances

sysstat_enable_data_collecting: true
26 changes: 26 additions & 0 deletions roles/diagnostic/files/htoprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=50 0 48 17 18 38 39 40 2 46 47 49 1
sort_key=111
sort_direction=1
hide_threads=1
hide_kernel_threads=1
hide_userland_threads=1
shadow_other_users=0
show_thread_names=0
show_program_path=1
highlight_base_name=0
highlight_megabytes=0
highlight_threads=0
tree_view=1
header_margin=1
detailed_cpu_time=1
cpu_count_from_zero=1
update_process_names=0
account_guest_in_cpu_meter=0
color_scheme=6
delay=15
left_meters=CPU AllCPUs
left_meter_modes=2 1
right_meters=Blank Clock Memory Swap
right_meter_modes=2 2 2 1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies:
public: true

galaxy_info:
description: Setup glances
description: Setup diagnostic tools
author: alexandermeindl
company: AlphaNodes GmbH
license: Apache License 2.0
Expand All @@ -16,8 +16,13 @@ galaxy_info:
- jammy
- name: Debian
versions:
- buster
- bullseye
- bookworm
galaxy_tags:
- atop
- bottom
- btop
- htop
- glances
- nmap
- sysstat
6 changes: 6 additions & 0 deletions roles/diagnostic/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

- name: Include setup tasks
ansible.builtin.import_tasks: setup.yml
tags:
- diagnostic
50 changes: 50 additions & 0 deletions roles/diagnostic/tasks/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---

- name: Set facts
ansible.builtin.set_fact:
managing_user: "{{ ansible_user | default(ansible_env.USER) }}"

# Update should never be updated here because user already exists,
# but we have to specify it because otherwise ansible user reset password to empty string
- name: Get user information for non-root
ansible.builtin.user:
name: '{{ managing_user }}'
update_password: on_create
state: present
register: user_infos
when: managing_user != 'root'

- name: Be sure diagnostic packages are installed
ansible.builtin.apt:
name: '{{ diagnostic_packages }}'
state: present

- name: Include setup atop tasks
ansible.builtin.import_tasks: setup_atop.yml
tags:
- atop

- name: Include setup bottom tasks
ansible.builtin.import_tasks: setup_bottom.yml
tags:
- bottom

- name: Include setup btop tasks
ansible.builtin.import_tasks: setup_btop.yml
tags:
- btop

- name: Include setup glances tasks
ansible.builtin.import_tasks: setup_glances.yml
tags:
- glances

- name: Include setup htop tasks
ansible.builtin.import_tasks: setup_htop.yml
tags:
- htop

- name: Include setup sysstat tasks
ansible.builtin.import_tasks: setup_sysstat.yml
tags:
- sysstat
26 changes: 26 additions & 0 deletions roles/diagnostic/tasks/setup_atop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

# see https://www.atoptool.nl/
# see https://github.com/Atoptool/atop

- name: Activated atop
when: diagnostic_with_atop
block:
- name: Be sure atop package are installed
ansible.builtin.apt:
name: atop
state: present

- name: Disabled atop
when: not diagnostic_with_atop
block:
- name: Remove atop packages
ansible.builtin.apt:
name: atop
purge: true
state: absent

- name: Remove atop user configuration
ansible.builtin.file:
path: "{{ '/root' if managing_user == 'root' else user_infos.home }}/.atoprc"
state: absent
20 changes: 20 additions & 0 deletions roles/diagnostic/tasks/setup_bottom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

# see https://github.com/ClementTsang/bottom

- name: Activated bottom
when: diagnostic_with_bottom
block:
- name: Be sure bottom package are installed
ansible.builtin.apt:
name: bottom
state: present

- name: Disabled bottom
when: not diagnostic_with_bottom
block:
- name: Remove bottom packages
ansible.builtin.apt:
name: bottom
purge: true
state: absent
25 changes: 25 additions & 0 deletions roles/diagnostic/tasks/setup_btop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---

# see https://github.com/aristocratos/btop

- name: Activated btop
when: diagnostic_with_btop
block:
- name: Be sure btop package are installed
ansible.builtin.apt:
name: btop
state: present

- name: Disabled btop
when: not diagnostic_with_btop
block:
- name: Remove btop packages
ansible.builtin.apt:
name: btop
purge: true
state: absent

- name: Remove btop user configuration
ansible.builtin.file:
path: "{{ '/root' if managing_user == 'root' else user_infos.home }}/.config/btop"
state: absent
48 changes: 48 additions & 0 deletions roles/diagnostic/tasks/setup_glances.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

# see https://github.com/nicolargo/glances

- name: Activated glances
when: diagnostic_with_glances
block:
- name: Use pip
when: glances_with_pip
block:
- name: Include python role
ansible.builtin.include_role:
name: alphanodes.setup.python
vars:
python_pip_packages: '{{ glances_pip_packages }}'
python_pip_default_venv: '{{ glances_pip_venv }}'

- name: Use debian package
when: not glances_with_pip
block:
- name: Be sure glances not installed with debian packages
ansible.builtin.apt:
name: glances
state: absent

- name: Remove obsolete glances without venv
ansible.builtin.file:
path: /usr/local/bin/glances
state: absent

- name: Disabled glances
when: not diagnostic_with_glances
block:
- name: Remove glances venv
ansible.builtin.file:
path: '{{ python_venv_parent }}/{{ glances_pip_venv }}'
state: absent

- name: Remove glance package
ansible.builtin.apt:
name: glances
purge: true
state: absent

- name: Remove glances user configuration
ansible.builtin.file:
path: "{{ '/root' if managing_user == 'root' else user_infos.home }}/.local/share/glances"
state: absent
34 changes: 34 additions & 0 deletions roles/diagnostic/tasks/setup_htop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---

# see https://github.com/htop-dev/htop

- name: Activated htop
when: diagnostic_with_htop
block:
- name: Be sure htop package are installed
ansible.builtin.apt:
name: htop
state: present

# @see https://haydenjames.io/htop-heres-how-to-customize-it/
- name: Install htop configration
ansible.builtin.copy:
src: htoprc
dest: "{{ '/root' if managing_user == 'root' else user_infos.home }}/.config/htop/"
mode: 0644
owner: '{{ managing_user }}'
group: "{{ 'root' if managing_user == 'root' else user_infos.group }}"

- name: Disabled htop
when: not diagnostic_with_htop
block:
- name: Remove htop packages
ansible.builtin.apt:
name: htop
purge: true
state: absent

- name: Remove htop user configuration
ansible.builtin.file:
path: "{{ '/root' if managing_user == 'root' else user_infos.home }}/.config/htop"
state: absent
20 changes: 20 additions & 0 deletions roles/diagnostic/tasks/setup_nmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

# see https://nmap.org/

- name: Activated nmap
when: diagnostic_with_nmap
block:
- name: Be sure nmap package are installed
ansible.builtin.apt:
name: nmap
state: present

- name: Disabled nmap
when: not diagnostic_with_nmap
block:
- name: Remove nmap packages
ansible.builtin.apt:
name: nmap
purge: true
state: absent
Loading

0 comments on commit 3502494

Please sign in to comment.