Skip to content

Commit

Permalink
Added support for Ubuntu
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvoxia committed Nov 30, 2024
1 parent be0da1d commit 98b96e1
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 9 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Ansible Role: NUT

[![Build Status](https://github.com/salvoxia/ansible-role-nut/workflows/Release/badge.svg)](https://github.com/Salvoxia/ansible-role-nut/actions/workflows/release.yml)
[![Build Status](https://github.com/salvoxia/ansible-role-nut/workflows/CI/badge.svg)](https://github.com/Salvoxia/ansible-role-nut/actions/workflows/ci.yml)
[![Ansible Galaxy Downloads](https://img.shields.io/badge/dynamic/json?color=blueviolet&label=Galaxy%20Downloads&query=%24.download_count&url=https%3A%2F%2Fgalaxy.ansible.com%2Fapi%2Fv1%2Froles%2F39518%2F%3Fformat%3Djson)](https://galaxy.ansible.com/ui/standalone/roles/salvoxia/nut/)

Installs and configures [NUT](http://networkupstools.org/) (Nework UPS
Expand All @@ -21,6 +20,18 @@ Install dependencies with
```shell
ansible-galaxy install -r requirements.yml
```

__Compatibility:__
This role is tested with
- Debian 11 Bullseye
- Debian 12 Bookworm
- Ubuntu 22.04 LTS Jammy Jellyfish
- Ubuntu 24.04 LTS Noble Numbat

By default, the role will check for a compatible operating system and version (any of the above). To disable that check, set the role variable `nut_verify_os` to `false`.
> [!CAUTION]
> When using this role on an unsupported operating system and installing NUT from source, the variable `__nut_apt_source` must be set to whatever URL to use in `sources.list` for a `deb-src` entry.
## Installing from Source

By default the role will install NUT using the package manager. If the system's package manager comes with an older NUT package, it is possible to install NUT from source. The role will automatically install all build dependencies, check out the desired source version, compile and install NUT from source.
Expand Down Expand Up @@ -452,13 +463,25 @@ Additional content to append to the `upsd.conf` file
Additional content to append to the `upsmon.conf` file
</td>
</tr>
<tr>
<td>

`nut_verify_os`
</td>
<td>

Flag indicating whether to check for a known compatible operating system and version. Set to `false` to use the role on untested operating systems.<br>
Default: `true`
</td>
</tr>
</table>


## Example Playbook

```yaml
- hosts: all
gather_facts: true
roles:
- role: salvoxia.nut
nut_users:
Expand Down
4 changes: 4 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ nut_enable_service: true
# Indicates whether to install or remove NUT
nut_state: present

# Flag indicating whether to check for a known compatible operating system and version;
# Set to false to run on untested OS
nut_verify_os: true

# Flag indicating whether to compile and install NUT from source instead of a package manager
nut_install_from_source: false
# Git source repository to use when installing NUT from source
Expand Down
16 changes: 16 additions & 0 deletions molecule/install_from_pkgmgr/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ platforms:
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2404
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2204
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
provisioner:
name: ansible
verifier:
Expand Down
16 changes: 16 additions & 0 deletions molecule/install_from_source/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ platforms:
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2404
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2204
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
provisioner:
name: ansible
verifier:
Expand Down
16 changes: 16 additions & 0 deletions molecule/switch_from_pkgmgr_to_source/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ platforms:
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2404
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2204
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
provisioner:
name: ansible
verifier:
Expand Down
16 changes: 16 additions & 0 deletions molecule/switch_from_source_to_pkgmgr/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ platforms:
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2404
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2204
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
provisioner:
name: ansible
verifier:
Expand Down
16 changes: 16 additions & 0 deletions molecule/uninstall_from_pkgmgr/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ platforms:
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2404
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2204
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
provisioner:
name: ansible
verifier:
Expand Down
16 changes: 16 additions & 0 deletions molecule/uninstall_from_source/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ platforms:
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2404
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
- name: ubuntu-2204
image: geerlingguy/docker-ubuntu2404-ansible
command: ${MOLECULE_DOCKER_COMMAND:-""}
pre_build_image: true
cgroupns_mode: host
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
provisioner:
name: ansible
verifier:
Expand Down
9 changes: 9 additions & 0 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---
- name: Verify operating system
ansible.builtin.assert:
that:
- __nut_is_supported_os is defined
- __nut_is_supported_os
- ansible_facts['distribution_major_version'] in __nut_supported_os_versions
fail_msg: "{{ ansible_facts['distribution'] }} {{ ansible_facts['distribution_major_version'] }} is not supoorted by this role! Try setting nut_verify_os to false!"
when: nut_verify_os

- name: Verify nut_state
ansible.builtin.assert:
that: nut_state in ['present', 'absent']
Expand Down
6 changes: 3 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- name: Include OS-specific variables.
ansible.builtin.include_vars: "{{ ansible_facts['distribution'] }}.yml"

- name: Verify variables
ansible.builtin.include_tasks: assert.yml

- name: Include OS-specific variables.
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"

- name: Define nut_packages.
ansible.builtin.set_fact:
nut_packages: "{{ __nut_packages | list }}"
Expand Down
16 changes: 13 additions & 3 deletions tasks/manage_install_from_source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

- name: Ensure debian source repository is added to sources.list
ansible.builtin.apt_repository:
repo: deb-src http://deb.debian.org/debian {{ ansible_distribution_release }} main
repo: deb-src {{ __nut_apt_source }} {{ ansible_distribution_release }} main
state: present

- name: Create dependency package and install build dependencies
Expand All @@ -77,6 +77,16 @@
template_path: "{{ role_path }}/templates/mk-build-deps_output.yml"
set_fact: build_deps_kg

- name: Workaround for Debian Slim based containers

Check failure on line 80 in tasks/manage_install_from_source.yml

View workflow job for this annotation

GitHub Actions / Lint

risky-file-permissions

File permissions unset or incorrect.
ansible.builtin.file:
path: /usr/share/man/man1
state: directory

- name: Workaround for Debian Slim based containers

Check failure on line 85 in tasks/manage_install_from_source.yml

View workflow job for this annotation

GitHub Actions / Lint

risky-file-permissions

File permissions unset or incorrect.
ansible.builtin.file:
path: /usr/share/man/man2
state: directory

- name: Install build dependencies
ansible.builtin.package:
deb: "{{ nut_dir.path }}/{{ build_deps_kg['build-deps-package'] }}"
Expand All @@ -88,8 +98,8 @@
block:
- name: Add drivers based one package name
ansible.builtin.set_fact:
nut_drivers: "{{ nut_drivers | union(nut_packages_to_drivers | selectattr(item, 'defined') | map(attribute=item)) }}"
when: nut_packages_to_drivers | selectattr(item, 'defined') | list | count > 0
nut_drivers: "{{ nut_drivers | union(__nut_packages_to_drivers | selectattr(item, 'defined') | map(attribute=item)) }}"
when: __nut_packages_to_drivers | selectattr(item, 'defined') | list | count > 0
with_items: "{{ nut_packages }}"

- name: Add dummy-ups driver to nut-drivers for uninstall purposes
Expand Down
7 changes: 6 additions & 1 deletion vars/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
__nut_packages:
- nut-client
- nut-server
__nut_is_supported_os: true
__nut_supported_os_versions:
- '11'
- '12'
__nut_apt_source: 'http://deb.debian.org/debian'

nut_packages_to_drivers:
__nut_packages_to_drivers:
- nut-i2c:
- asem
- nut-ipmi:
Expand Down
28 changes: 28 additions & 0 deletions vars/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
__nut_packages:
- nut-client
- nut-server
__nut_is_supported_os: true
__nut_supported_os_versions:
- '22'
- '24'
__nut_apt_source: 'http://archive.ubuntu.com/ubuntu'

__nut_packages_to_drivers:
- nut-i2c:
- asem
- nut-ipmi:
- nut-ipmipsu
- nut-modbus:
- adelsystem_cbi
- apc_modbus
- generic_modbus
- huawei-ups2000
- phoenixcontact_modbus
- socomec_jbus
- nut-powerman-pdu:
- powerman-pdu
- nut-snmp:
- snmp-ups
- nut-xml:
- netxml-ups

0 comments on commit 98b96e1

Please sign in to comment.