Installs and configures NUT (Nework UPS
tools) on Debian based systems, while allowing for advanced NUT user configuration.
Also supports installing NUT from source tags to gain access to more up-to-date versions if the system's package manager does not provide them.
Key Features:
- Set
nut_state
to either install or remove NUT - Allow for advanced NUT user configuration with detailed permission management
- Install NUT from a specific source tag instead of package manager in case the package manager provided version is too old
- Switch between specific versions installed from source
- Switch between installation from package manager and source (or vice versa)
Dependencies:
Install dependencies with
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.
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.
It is also possible to use this role for updating NUT installed from source to a newer version (or downgrade to an older version). It is not a 'real' upgrade, but the old version is uninstalled before the new version is installed.
The role supports switching between NUT installed by package manager and installed from source (and vice versa).
The following variables control installation from source:
Variable | Description |
---|---|
|
Flag indicating whether to install NUT from source or not. All the variables below have no effect if not set to true .Default: false
|
|
The URL to the Git Repository to compile NUT from. Default: https://github.com/networkupstools/nut.git
|
|
The Git Tag to check out before compiling NUT. Can be a branch name as well. Default: v2.8.2
|
|
A list of NUT driver names to compile NUT. For a list fo valid drivers refer to the Drivers section in the generic manual for unified NUT driversExample: nut_drivers:
- snmp-ups
- netxml-ups |
Available variables are listed below, along with default values (see
defaults/main.yml
).
nut_mode: standalone
The NUT MODE
setting in nut.conf
.
Allowed values in this role are standalone
, netserver
or netclient
.
nut_managed_config: true
If this is set to false, none of the following options will have any
effect, that is any and all changes under /etc/nut/
will be your
responsibility. This is often desirable when you have complex
configurations.
This role allows for configuring different NUT users with specific actions
and instcmds
. These only have effect if nut_mode
is set to either netserver
or standalone
.
The minimal user configuration looks like this:
nut_users:
- name: monitor
password: Whatever
role: secondary
A full user configuration might look like this:
nut_users:
- name: monitor
password: Changeme
role: secondary
- name: admin
password: uNro<FQ.eav:fyc^.,>,b29/4Dts=9
role: primary
actions:
- fsd
- set
instcmds:
- all
Explanation for all possible attributes:
Attribute | Description |
---|---|
|
Name for the NUT user |
|
The user's password Mandatory |
|
Either the |
|
Used to set allowed actions for the user in |
|
Used to set allowed instant commands for the user in |
The nut_ups
variable is a list of UPS definitions the NUT installation knows of. Depening on nut_mode
, the minimal set of attributes differs.
For nut_mode = netclient
, the minimal UPS configuration looks like this:
nut_ups:
- name: UPS
monitoruser: monitor
For nut_mode = netserver
or nut_mode = standalone
, the minimal UPS configuration looks like this:
nut_ups:
- name: UPS
monitoruser: monitor
driver: usbhid-ups
device: auto
The full configuration for nut_ups
with all possible attributes looks like this:
nut_ups:
- name: UPS
monitoruser: monitor
driver: usbhid-ups
device: auto
description: Some descriptive information
monitorhost: localhost
powervalue: 1
extra: |
maxretry = 10
retrydelay = 1
Explanation for all possible attributes:
Attribute | Description |
---|---|
|
An arbitrary string that must identify univocally the UPS |
|
The NUT user to use for monitoring this UPS. Must reference an existing user defined in nut_users .Mandatory |
|
Depends on your hardware and must be one of the available NUT driver. Be sure the NUT version installed on your server has that specific driver available |
|
Port where the UPS is listening (typically an USB port or a serial device). It is translated to the |
|
An arbitrary string used for debugging and reporting purposes |
|
The host that UPS can be monitored with. Is used as the host in the |
|
The number of power supplies that the UPS feeds on this system. Is used as |
|
|
All these variables are optional:
Variable | Description |
---|---|
|
Flag indicating whether to start the services appropriate for the installed |
|
Contents of a custom |
|
Path on the Ansible host to a custom |
|
Sets the |
|
Sets the |
|
Define nut_upssched_at_commands:
- notifytype: ONBATT
upsname: *
command: START-TIMER commbad 30 |
|
Define custom nut_upsmon_notify:
- name: ONLINE
msg: UPS %s on line power
flag: SYSLOG+WALL+EXEC
- name: ONBATT
msg: UPS %s on battery
flag: SYSLOG+WALL+EXEC |
|
Contents of a custom upsmon notification script. |
|
Path to a custom notification script. Sets the |
|
Additional content to append to the |
|
Additional content to append to the |
|
Additional content to append to the |
|
Flag indicating whether to check for a known compatible operating system and version. Set to |
- hosts: all
gather_facts: true
roles:
- role: salvoxia.nut
nut_users:
- name: monitor
password: changeme
role: secondary
nut_ups:
- name: riello
monitoruser: monitor
driver: riello_usb
device: /dev/ups
description: iPlug 800
For more examples, please see molecule/*/converge.yml
and molecule/*/prepare.yml
.
Run a Docker container with systemd:
sudo docker run --tmpfs /tmp --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --privileged --name sysd --rm geerlingguy/docker-debian11-ansible
MIT
This role was created in 2016 by Nicola Fontana ([email protected]).
This fork is modified and maintained by Salvoxia ([email protected]).