first commit
26
README.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
Configuration Management Database
|
||||
=================================
|
||||
|
||||
Diese Rolle erstellt CMDB innerhalb eines vorhandenen Dokuwikis.
|
||||
|
||||
## Installation
|
||||
Führe die Rolle mit dem `install`-Tag aus:
|
||||
```Shell
|
||||
ansible-playbook playbooks/cmdb.yml --tags install
|
||||
```
|
||||
|
||||
## Erstellung / Aktualisierung der Einträge
|
||||
Führe die Rolle ohne `install`-Tag aus:
|
||||
```Shell
|
||||
ansible-playbook playbooks/cmdb.yml --skip-tags install
|
||||
```
|
||||
|
||||
## Variablen
|
||||
|
||||
| Variable Name | Function | Default value | File | Comment |
|
||||
| ------------- | -------- | ------------- | ---- | ------- |
|
||||
| `cmdb` | Dictionary for dokuwiki server variables _(required)_ | -- | `group_vars/all/cmdb.yml` |
|
||||
| `cmdb.wiki_server` | dokuwiki server _(required)_ | -- | `group_vars/all/cmdb.yml` |
|
||||
| `cmdb.wiki_pages_path` | path for wiki pages on dokuwiki server _(required)_ | -- | `group_vars/all/cmdb.yml` |
|
||||
| `cmdb.wiki_media_path` | path for media on dokuwiki server _(required)_ | -- | `group_vars/all/cmdb.yml` |
|
||||
| `cmdb.wiki_meta_path` | path for metadata on dokuwiki server _(required)_ | -- | `group_vars/all/cmdb.yml` |
|
BIN
files/logos/apache.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
files/logos/borg.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
files/logos/docker.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
files/logos/kvm.png
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
files/logos/mariadb.png
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
files/logos/nginx.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
files/logos/php.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
files/logos/postgresql.png
Normal file
After Width: | Height: | Size: 21 KiB |
BIN
files/logos/rails.png
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
files/logos/tinc.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
files/logos/tor.png
Normal file
After Width: | Height: | Size: 13 KiB |
10
meta/main.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
galaxy_info:
|
||||
author: Sense.Lab e.V. admins
|
||||
description: Configures a cmdb
|
||||
company: Sense.Lab e.V.
|
||||
license: GPLv3
|
||||
min_ansible_version: "2.11"
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- bookworm
|
34
tasks/hypervisor.yml
Normal file
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
- name: "Hypervisor | Scrap virtual machines"
|
||||
ansible.builtin.command: "virsh list --all"
|
||||
register: command_out
|
||||
changed_when: false
|
||||
|
||||
- name: "Hypervisor | Set VM fact"
|
||||
ansible.builtin.set_fact:
|
||||
qemu_vms: "{{ command_out.stdout }}"
|
||||
|
||||
- name: "Hypervisor | scrap virtual networks"
|
||||
ansible.builtin.command: "virsh net-list --all"
|
||||
register: command_out
|
||||
changed_when: false
|
||||
|
||||
- name: "Hypervisor | Set network fact"
|
||||
ansible.builtin.set_fact:
|
||||
qemu_network: "{{ command_out.stdout }}"
|
||||
|
||||
- name: "Hypervisor | Scrap virtual storage pools"
|
||||
ansible.builtin.command: "virsh pool-list --all"
|
||||
register: command_out
|
||||
changed_when: false
|
||||
|
||||
- name: "Hypervisor | Set storage fact"
|
||||
ansible.builtin.set_fact:
|
||||
qemu_pool: "{{ command_out.stdout }}"
|
||||
|
||||
- name: "Hypervisor | Write hypervisor startpage"
|
||||
ansible.builtin.template:
|
||||
src: hypervisor.txt.j2
|
||||
dest: "{{ cmdb.wiki_pages_path }}/servers/hypervisor.txt"
|
||||
mode: "0644"
|
||||
delegate_to: "{{ cmdb.wiki_server }}"
|
26
tasks/install.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
- name: "Install | Setup Wiki folder structur"
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
mode: "{{ cmdb.wiki_dir_mode }}"
|
||||
owner: "{{ cmdb.wiki_user }}"
|
||||
group: "{{ cmdb.wiki_group }}"
|
||||
run_once: true
|
||||
loop:
|
||||
- "{{ cmdb.wiki_pages_path }}"
|
||||
- "{{ cmdb.wiki_pages_path }}/servers"
|
||||
- "{{ cmdb.wiki_pages_path }}/servers/all"
|
||||
- "{{ cmdb.wiki_pages_path }}/servers/hypervisor"
|
||||
|
||||
- name: "Install | Upload logos"
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ cmdb.wiki_media_path }}/"
|
||||
mode: "{{ cmdb.wiki_dir_mode }}"
|
||||
owner: "{{ cmdb.wiki_user }}"
|
||||
group: "{{ cmdb.wiki_group }}"
|
||||
run_once: true
|
||||
loop: "{{ lookup('fileglob', 'logos/*', wantlist=True) }}"
|
||||
tags:
|
||||
- logos
|
27
tasks/main.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
- name: Initiate cmdb
|
||||
ansible.builtin.import_tasks: install.yml
|
||||
delegate_to: "{{ cmdb.wiki_server }}"
|
||||
tags: install
|
||||
|
||||
- name: Gather facts
|
||||
ansible.builtin.package_facts:
|
||||
manager: auto
|
||||
tags: facts
|
||||
|
||||
- name: Create 'virt_kvm_host' group
|
||||
ansible.builtin.group_by:
|
||||
key: virt_{{ ansible_virtualization_type }}_{{ ansible_virtualization_role }}
|
||||
tags: facts
|
||||
|
||||
- name: Create hypervisor items
|
||||
ansible.builtin.import_tasks: hypervisor.yml
|
||||
when: "'qemu-system-x86' in ansible_facts.packages"
|
||||
tags:
|
||||
- hypervisor
|
||||
- server
|
||||
|
||||
- name: Create server items
|
||||
ansible.builtin.import_tasks: server.yml
|
||||
delegate_to: "{{ cmdb.wiki_server }}"
|
||||
tags: server
|
19
tasks/server.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
- name: "Server | Write server startpage"
|
||||
ansible.builtin.template:
|
||||
src: servers.txt.j2
|
||||
dest: "{{ cmdb.wiki_pages_path }}/servers.txt"
|
||||
mode: "0644"
|
||||
|
||||
- name: "Server | Write startpage for all servers"
|
||||
ansible.builtin.template:
|
||||
src: all.txt.j2
|
||||
dest: "{{ cmdb.wiki_pages_path }}/servers/all.txt"
|
||||
mode: "0644"
|
||||
|
||||
- name: "Server | Write server item"
|
||||
ansible.builtin.template:
|
||||
src: item.txt.j2
|
||||
dest: "{{ cmdb.wiki_pages_path }}/servers/all/{{ inventory_hostname }}.txt"
|
||||
mode: "0644"
|
||||
tags: server_item
|
5
templates/all.txt.j2
Normal file
|
@ -0,0 +1,5 @@
|
|||
====== Alle Server ======
|
||||
|
||||
{% for host in groups['all'] | sort %}
|
||||
* [[cmdb:servers:all:{{ host }}]]
|
||||
{% endfor %}
|
5
templates/hypervisor.txt.j2
Normal file
|
@ -0,0 +1,5 @@
|
|||
====== Hypervisor ======
|
||||
|
||||
{% for host in groups['virt_kvm_host'] %}
|
||||
* [[cmdb:servers:all:{{ host }}]]
|
||||
{% endfor %}
|
60
templates/item.txt.j2
Normal file
|
@ -0,0 +1,60 @@
|
|||
{% set host_short = inventory_hostname.split('.')[0] %}
|
||||
|
||||
{%- if ansible_virtualization_role is defined %}{{'{{:cmdb:kvm.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'nginx' in ansible_facts.packages %}{{'{{:cmdb:nginx.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'apache2' in ansible_facts.packages %}{{'{{:cmdb:apache.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'docker' in ansible_facts.packages %}{{'{{:cmdb:docker.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'php' in ansible_facts.packages %}{{'{{:cmdb:php.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'ruby' in ansible_facts.packages %}{{'{{:cmdb:rails.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'mariadb-server' in ansible_facts.packages %}{{'{{:cmdb:mariadb.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'postgresql' in ansible_facts.packages %}{{'{{:cmdb:postgresql.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'tinc' in ansible_facts.packages %}{{'{{:cmdb:tinc.png?0x50|}}'}}{% endif %}
|
||||
{%- if 'tor' in ansible_facts.packages %}{{'{{:cmdb:tor.png?0x50|}}'}}{% endif %}
|
||||
|
||||
====== {{ inventory_hostname }} =======
|
||||
|
||||
{% include 'section_header.txt.j2' %}
|
||||
|
||||
{% if cmdb_customer is defined %}
|
||||
{% include 'section_customer.txt.j2' %}
|
||||
{% endif %}
|
||||
|
||||
{% include 'section_general.txt.j2' %}
|
||||
|
||||
{% include 'section_os-software.txt.j2' %}
|
||||
|
||||
{% if ansible_virtualization_role is undefined or ansible_virtualization_role == "host" %}
|
||||
{% include 'section_block_devices.txt.j2' %}
|
||||
{% endif %}
|
||||
|
||||
{% include 'section_mounted_fs.txt.j2' %}
|
||||
|
||||
{% include 'section_networking.txt.j2' %}
|
||||
|
||||
{% if "qemu-system-x86" in ansible_facts.packages %}
|
||||
===== KVM =====
|
||||
==== Virtual machines ====
|
||||
|
||||
{% if qemu_vms is defined %}
|
||||
<code>
|
||||
{{ qemu_vms }}
|
||||
</code>
|
||||
{% endif %}
|
||||
|
||||
==== Virtual networks ====
|
||||
|
||||
{% if qemu_network is defined %}
|
||||
<code>
|
||||
{{ qemu_network }}
|
||||
</code>
|
||||
{% endif %}
|
||||
|
||||
==== Storage pools ====
|
||||
|
||||
{% if qemu_pool is defined %}
|
||||
<code>
|
||||
{{ qemu_pool }}
|
||||
</code>
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
8
templates/section_block_devices.txt.j2
Normal file
|
@ -0,0 +1,8 @@
|
|||
===== Block devices =====
|
||||
|
||||
^ Model ^ Type ^ Size ^
|
||||
{% for device_name, device_info in ansible_facts.devices.items() %}
|
||||
{% if "nvme" in device_name or "sd" in device_name or "sr" in device_name %}
|
||||
| {{ device_info.model }} | {% if "nvme" in device_name %}NVMe{% else %}SSD/HDD{% endif %} | {{ device_info.size }} |
|
||||
{% endif %}
|
||||
{% endfor %}
|
6
templates/section_customer.txt.j2
Normal file
|
@ -0,0 +1,6 @@
|
|||
===== Customer =====
|
||||
|
||||
* Customer: {{ cmdb_customer }}
|
||||
{% if cmdb_customer_service_agreement is defined %}
|
||||
* Service Agreement: {{ cmdb_customer_service_agreement }}
|
||||
{% endif %}
|
9
templates/section_general.txt.j2
Normal file
|
@ -0,0 +1,9 @@
|
|||
===== General =====
|
||||
|
||||
* Server Type: {% if ansible_virtualization_role == "guest" %} virtual {% else %} bare metal ({{ ansible_chassis_vendor }}){% endif %}
|
||||
|
||||
* Virtualization: {{ ansible_virtualization_type }}
|
||||
* Architecture: ''{{ ansible_machine }}''
|
||||
* RAM: ''{{ (ansible_memtotal_mb / 1024) | round(2) }} GB''
|
||||
* CPU: {{ ansible_processor_vcpus }} calc units ({{ ansible_processor_count }} processors with {{ ansible_processor_cores }} cores and {{ ansible_processor_threads_per_core }} threads/core)
|
||||
* CPU model: {% for line in ansible_processor %}{% if loop.index is not divisibleby 2 %}{{ line }}, {% endif %}{% endfor %}
|
2
templates/section_header.txt.j2
Normal file
|
@ -0,0 +1,2 @@
|
|||
* CMDB-Eintrag aktualisiert am: {{ ansible_date_time.date }} {{ ansible_date_time.time }}
|
||||
* [[{{ cmdb.wiki_server_documentation_path }}:{{ inventory_hostname }}|Dokumentation]]
|
6
templates/section_mounted_fs.txt.j2
Normal file
|
@ -0,0 +1,6 @@
|
|||
===== Mounted file systems =====
|
||||
|
||||
^ Device ^ Mount point ^ File system ^ Size ^
|
||||
{% for item in ansible_mounts %}
|
||||
| {{ item.device }} | {{ item.mount }} | {{ item.fstype }} | {{ item.size_total | human_readable(unit="G") }} |
|
||||
{% endfor %}
|
47
templates/section_networking.txt.j2
Normal file
|
@ -0,0 +1,47 @@
|
|||
===== Networking =====
|
||||
==== Uplink ====
|
||||
|
||||
{% if ansible_facts['default_ipv6']['address'] is defined %}
|
||||
**IPv6:**
|
||||
|
||||
* Address: ''{{ ansible_facts['default_ipv6']['address'] }}''
|
||||
* Prefix: ''{{ ansible_facts['default_ipv6']['prefix'] }}''
|
||||
* Gateway: {% if ansible_facts['default_ipv6']['gateway'] is defined %}''{{ ansible_facts['default_ipv6']['gateway'] }}''{% else %}no gateway{% endif %}
|
||||
|
||||
* Interface: ''{{ ansible_facts['default_ipv6']['interface'] }}''
|
||||
* MTU: ''{{ ansible_facts['default_ipv6']['mtu'] }}''
|
||||
{% endif %}
|
||||
|
||||
{% if ansible_facts['default_ipv4']['address'] is defined %}
|
||||
**IPv4:**
|
||||
|
||||
* Network type: {% if (ansible_facts['default_ipv4']['address'] | ansible.utils.ipaddr('public')) %}//public//{% else %}//private//{% endif %}
|
||||
|
||||
* Address: ''{{ ansible_facts['default_ipv4']['address'] }}''
|
||||
* Gateway: {% if ansible_facts['default_ipv4']['gateway'] is defined %}''{{ ansible_facts['default_ipv4']['gateway'] }}''{% else %}no gateway{% endif %}
|
||||
|
||||
* Interface: ''{{ ansible_facts['default_ipv4']['interface'] }}''
|
||||
* MTU: ''{{ ansible_facts['default_ipv4']['mtu'] }}''
|
||||
{% endif %}
|
||||
|
||||
==== Other ====
|
||||
|
||||
**IPv6 addresses:**
|
||||
|
||||
{% for address in ansible_facts['all_ipv6_addresses'] %}
|
||||
* ''{{ address }}'' {% if (address | ansible.utils.ipaddr('public')) %}//public//{% else %}//private//{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
**IPv4 addresses:**
|
||||
|
||||
{% for address in ansible_facts['all_ipv4_addresses'] %}
|
||||
* ''{{ address }}'' {% if (address | ansible.utils.ipaddr('public')) %}//public//{% else %}//private//{% endif %}
|
||||
|
||||
{% endfor %}
|
||||
|
||||
**network interfaces:**
|
||||
|
||||
{% for interface in ansible_facts['interfaces'] %}
|
||||
* ''{{ interface }}''
|
||||
{% endfor %}
|
7
templates/section_os-software.txt.j2
Normal file
|
@ -0,0 +1,7 @@
|
|||
===== OS/Software =====
|
||||
|
||||
* Distribution: {{ ansible_distribution }}
|
||||
* Version: ''{{ ansible_distribution_version }}'' ({{ ansible_distribution_release }})
|
||||
* Kernel: ''{{ ansible_kernel }}''
|
||||
* Apparmor: ''{{ ansible_facts.apparmor.status }}''
|
||||
* Main python version: ''{{ ansible_python_version }}''
|
4
templates/servers.txt.j2
Normal file
|
@ -0,0 +1,4 @@
|
|||
===== Server =====
|
||||
|
||||
* [[cmdb:servers:all|Alle Server]]
|
||||
* [[cmdb:servers:hypervisor|Hypervisor]]
|