feat: initial installation role for librenms
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.retry
|
||||||
46
README.md
Normal file
46
README.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# ansible-role-librenms
|
||||||
|
|
||||||
|
Installs LibreNMS from GitHub releases on Debian-based distributions. Handles
|
||||||
|
package dependencies, PHP Composer install, file permissions, cron jobs and
|
||||||
|
the systemd dispatcher service.
|
||||||
|
|
||||||
|
The following are out of scope and must be handled separately:
|
||||||
|
- Database (MariaDB/MySQL) setup and LibreNMS database migration
|
||||||
|
- nginx/apache virtual host configuration
|
||||||
|
- LibreNMS `.env` application configuration
|
||||||
|
|
||||||
|
The service is left disabled/stopped by default until the database and
|
||||||
|
config are in place.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Ansible >= 2.14
|
||||||
|
- Debian Bookworm or Ubuntu Jammy/Noble
|
||||||
|
- The `librenms_user` and `librenms_group` must be created beforehand
|
||||||
|
|
||||||
|
## Role Variables
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
|---|---|---|
|
||||||
|
| `librenms_version` | `""` | Version to install (empty = latest) |
|
||||||
|
| `librenms_user` | `librenms` | User to own the installation |
|
||||||
|
| `librenms_group` | `librenms` | Group to own the installation |
|
||||||
|
| `librenms_install_dir` | `/opt/librenms` | Installation directory |
|
||||||
|
| `librenms_php_version` | `"8.2"` | PHP version to install |
|
||||||
|
| `librenms_service_enabled` | `false` | Enable dispatcher at boot |
|
||||||
|
| `librenms_service_state` | `stopped` | Service state (needs DB config first) |
|
||||||
|
|
||||||
|
## Example Playbook
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- hosts: monitoring_servers
|
||||||
|
roles:
|
||||||
|
- role: ansible-role-librenms
|
||||||
|
vars:
|
||||||
|
librenms_user: librenms
|
||||||
|
librenms_group: librenms
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
8
defaults/main.yml
Normal file
8
defaults/main.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
librenms_version: ""
|
||||||
|
librenms_user: librenms
|
||||||
|
librenms_group: librenms
|
||||||
|
librenms_install_dir: /opt/librenms
|
||||||
|
librenms_php_version: "8.2"
|
||||||
|
librenms_service_enabled: false
|
||||||
|
librenms_service_state: stopped
|
||||||
1
handlers/main.yml
Normal file
1
handlers/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
13
meta/main.yml
Normal file
13
meta/main.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
galaxy_info:
|
||||||
|
author: mathieu
|
||||||
|
description: Install LibreNMS on Debian-based distributions
|
||||||
|
license: MIT
|
||||||
|
min_ansible_version: "2.14"
|
||||||
|
platforms:
|
||||||
|
- name: Debian
|
||||||
|
versions: [bookworm]
|
||||||
|
- name: Ubuntu
|
||||||
|
versions: [jammy, noble]
|
||||||
|
galaxy_tags: [librenms, monitoring, snmp]
|
||||||
|
dependencies: []
|
||||||
190
tasks/main.yml
Normal file
190
tasks/main.yml
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
---
|
||||||
|
- name: Assert Debian-based distribution
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- ansible_os_family == 'Debian'
|
||||||
|
fail_msg: "ansible-role-librenms only supports Debian-based distributions"
|
||||||
|
|
||||||
|
- name: Install LibreNMS system dependencies
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name:
|
||||||
|
- acl
|
||||||
|
- curl
|
||||||
|
- fping
|
||||||
|
- git
|
||||||
|
- graphviz
|
||||||
|
- imagemagick
|
||||||
|
- mariadb-client
|
||||||
|
- mtr-tiny
|
||||||
|
- nginx-light
|
||||||
|
- nmap
|
||||||
|
- "php{{ librenms_php_version }}-cli"
|
||||||
|
- "php{{ librenms_php_version }}-curl"
|
||||||
|
- "php{{ librenms_php_version }}-fpm"
|
||||||
|
- "php{{ librenms_php_version }}-gd"
|
||||||
|
- "php{{ librenms_php_version }}-gmp"
|
||||||
|
- "php{{ librenms_php_version }}-mbstring"
|
||||||
|
- "php{{ librenms_php_version }}-mysql"
|
||||||
|
- "php{{ librenms_php_version }}-snmp"
|
||||||
|
- "php{{ librenms_php_version }}-xml"
|
||||||
|
- "php{{ librenms_php_version }}-zip"
|
||||||
|
- "php{{ librenms_php_version }}-bcmath"
|
||||||
|
- "php{{ librenms_php_version }}-ldap"
|
||||||
|
- "php{{ librenms_php_version }}-sockets"
|
||||||
|
- python3
|
||||||
|
- python3-dotenv
|
||||||
|
- python3-pymysql
|
||||||
|
- python3-redis
|
||||||
|
- python3-setuptools
|
||||||
|
- python3-systemd
|
||||||
|
- rrdtool
|
||||||
|
- snmp
|
||||||
|
- snmpd
|
||||||
|
- unzip
|
||||||
|
- whois
|
||||||
|
state: present
|
||||||
|
update_cache: true
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Install Composer
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: >
|
||||||
|
curl -sS https://getcomposer.org/installer
|
||||||
|
| php -- --install-dir=/usr/local/bin --filename=composer
|
||||||
|
creates: /usr/local/bin/composer
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Get LibreNMS release info from GitHub
|
||||||
|
ansible.builtin.uri:
|
||||||
|
url: >-
|
||||||
|
{{ 'https://api.github.com/repos/librenms/librenms/releases/latest'
|
||||||
|
if librenms_version == ''
|
||||||
|
else 'https://api.github.com/repos/librenms/librenms/releases/tags/' + librenms_version }}
|
||||||
|
headers:
|
||||||
|
Accept: "application/vnd.github.v3+json"
|
||||||
|
return_content: true
|
||||||
|
register: _librenms_release
|
||||||
|
|
||||||
|
- name: Set LibreNMS version tag fact
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
_librenms_version_tag: "{{ _librenms_release.json.tag_name }}"
|
||||||
|
|
||||||
|
- name: Read installed version
|
||||||
|
ansible.builtin.slurp:
|
||||||
|
src: "{{ librenms_install_dir }}/.version"
|
||||||
|
register: _librenms_installed_raw
|
||||||
|
ignore_errors: true
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Set installed version fact
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
_librenms_installed_version: >-
|
||||||
|
{{ (_librenms_installed_raw.content | b64decode | trim)
|
||||||
|
if _librenms_installed_raw is not failed else '' }}
|
||||||
|
|
||||||
|
- name: Install or upgrade LibreNMS
|
||||||
|
when: _librenms_installed_version != _librenms_version_tag
|
||||||
|
block:
|
||||||
|
- name: Download LibreNMS source archive
|
||||||
|
ansible.builtin.get_url:
|
||||||
|
url: "https://github.com/librenms/librenms/archive/refs/tags/{{ _librenms_version_tag }}.tar.gz"
|
||||||
|
dest: /tmp/librenms.tar.gz
|
||||||
|
mode: '0644'
|
||||||
|
|
||||||
|
- name: Create LibreNMS installation directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ librenms_install_dir }}"
|
||||||
|
state: directory
|
||||||
|
owner: "{{ librenms_user }}"
|
||||||
|
group: "{{ librenms_group }}"
|
||||||
|
mode: '0771'
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Extract LibreNMS archive
|
||||||
|
ansible.builtin.unarchive:
|
||||||
|
src: /tmp/librenms.tar.gz
|
||||||
|
dest: "{{ librenms_install_dir }}"
|
||||||
|
remote_src: true
|
||||||
|
extra_opts: [--strip-components=1]
|
||||||
|
owner: "{{ librenms_user }}"
|
||||||
|
group: "{{ librenms_group }}"
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Install PHP dependencies via Composer
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: /usr/local/bin/composer install --no-dev --no-interaction
|
||||||
|
chdir: "{{ librenms_install_dir }}"
|
||||||
|
become: true
|
||||||
|
become_user: "{{ librenms_user }}"
|
||||||
|
|
||||||
|
- name: Write installed version file
|
||||||
|
ansible.builtin.copy:
|
||||||
|
content: "{{ _librenms_version_tag }}"
|
||||||
|
dest: "{{ librenms_install_dir }}/.version"
|
||||||
|
owner: "{{ librenms_user }}"
|
||||||
|
group: "{{ librenms_group }}"
|
||||||
|
mode: '0644'
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Remove downloaded archive
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /tmp/librenms.tar.gz
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Set ACL on LibreNMS directories
|
||||||
|
ansible.builtin.command:
|
||||||
|
cmd: "{{ item }}"
|
||||||
|
become: true
|
||||||
|
changed_when: true
|
||||||
|
loop:
|
||||||
|
- "setfacl -d -m g::rwx {{ librenms_install_dir }}/rrd {{ librenms_install_dir }}/logs {{ librenms_install_dir }}/bootstrap/cache {{ librenms_install_dir }}/storage"
|
||||||
|
- "setfacl -R -m g::rwx {{ librenms_install_dir }}/rrd {{ librenms_install_dir }}/logs {{ librenms_install_dir }}/bootstrap/cache {{ librenms_install_dir }}/storage"
|
||||||
|
|
||||||
|
- name: Add librenms cron job
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ librenms_install_dir }}/dist/librenms.cron"
|
||||||
|
dest: /etc/cron.d/librenms
|
||||||
|
remote_src: true
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Install LibreNMS logrotate config
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ librenms_install_dir }}/misc/librenms.logrotate"
|
||||||
|
dest: /etc/logrotate.d/librenms
|
||||||
|
remote_src: true
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Install LibreNMS systemd dispatcher service
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ librenms_install_dir }}/dist/librenms.service"
|
||||||
|
dest: /etc/systemd/system/librenms.service
|
||||||
|
remote_src: true
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Install LibreNMS systemd dispatcher socket
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: "{{ librenms_install_dir }}/dist/librenms.socket"
|
||||||
|
dest: /etc/systemd/system/librenms.socket
|
||||||
|
remote_src: true
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: '0644'
|
||||||
|
become: true
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Enable LibreNMS dispatcher service
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: librenms
|
||||||
|
enabled: "{{ librenms_service_enabled }}"
|
||||||
|
state: "{{ librenms_service_state }}"
|
||||||
|
daemon_reload: true
|
||||||
|
become: true
|
||||||
Reference in New Issue
Block a user