--- - 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