Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleepy-nols/ansible_role_nut
Ansible role to install and configure NUT on Debian-like systems, plus automatically connecting servers and clients together.
https://github.com/sleepy-nols/ansible_role_nut
ansible ansible-role nut ups
Last synced: about 1 month ago
JSON representation
Ansible role to install and configure NUT on Debian-like systems, plus automatically connecting servers and clients together.
- Host: GitHub
- URL: https://github.com/sleepy-nols/ansible_role_nut
- Owner: sleepy-nols
- License: gpl-3.0
- Created: 2024-05-19T22:49:53.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-09-10T20:35:26.000Z (2 months ago)
- Last Synced: 2024-09-30T17:23:27.800Z (about 2 months ago)
- Topics: ansible, ansible-role, nut, ups
- Language: Jinja
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ansible Network UPS Tools
Ansible role to install and configure [NUT](https://networkupstools.org) on Debian-like systems, plus automatically connecting servers and clients together.
This role configures part of its automation over the Ansible inventory. You need to therefore configure it correct for this role to work. The [example configuration](/#) is a minimum set that needs to exist.
This role uses the terminology `server` and `client` instead of `master` and `slave`.
---
What it does:
- automatic connection of clientsa and servers
- automatic instance mode selection
- currently only supports 1 ups per serverAssumptions made:
- clients can reach server via its default ip address (e.g. local network or vpn)Client and server devices are seperated into two inventory groups: `[nut_clients]` and `[nut_servers]`. Accordingly client hosts should be present in the inventory group `[nut_clients]` and server hosts in `[nut_server]`.
Host enters configuration mode when:
**standalone:**
- the host is in inventory group `[nut_servers]`
- no host that is member of inventory group `[nut_clients]` marks the host as `nut_server_member=`**netserver:**
- the host is in inventory group `[nut_servers]`
- one ore more hosts that are member of inventory group `[nut_clients]` mark the host as `nut_server_member=`**netclient:**
- the host is in inventory group `[nut_clients]`
- the host marks a host which is member of inventory group `[nut_servers]` with `nut_server_member=`---
## Example configuration
```yml
# inventory/host_vars/nut-server01.yml
nut_ups_devices:
mydevice: # <-- unique device identifyer
driver: "usbhid-ups" # https://networkupstools.org/stable-hcl.html
port: "auto"
desc: "some description"
```
Example **server** hostvars file.
```yml
# inventory/nut[nut_all:children]
nut_servers
nut_clients[nut_servers]
nut-server01 nut_master_password="secretpassword"[nut_clients]
nut-client01 nut_server_member="nut-server01" nut_password="secretpassword"
nut-client02 nut_server_member="nut-server01" nut_password="secretpassword"```
Example **inventory** file. Variables can alternatively be set in hostvars.
```yml
# playbooks/nut.yml
---
- name: Build variables locally
hosts: localhost
pre_tasks:- name: Prepare variables
ansible.builtin.set_fact:
nut_server_client_map: {}
nut_client_list: []- name: block
block:
- name: Build checks
ansible.builtin.set_fact:
test: "{% for client in groups['nut_clients'] %}{% if hostvars[client]['nut_server_member'] %}{% endif %}{% endfor %}"
rescue:
- assert:
that: false
msg: "A nut client is probably missing the nut_server_member variable."- name: Build server - client tree
ansible.builtin.set_fact:
nut_server_client_map: "{% for client in groups['nut_clients'] %}{% if hostvars[client]['nut_server_member'] == item %}{% set _ = nut_client_list.append(client) %}{% endif %}{% endfor %}{{ {item: nut_client_list} | combine(nut_server_client_map) }}"
loop: "{{ groups['nut_servers'] }}"- name: Show server - client tree
debug:
msg: "{{ nut_server_client_map }}"- name: "Install and configure NUT on servers and clients"
hosts: nut_all
roles:
- ansible_role_nut
```
Example **playbook**.
---
## Related
Ansible Role - Prometheus NUT Exporter https://gitlab.com/sleepy_nols/ansible_role_nut_exporter/
## License
GPLv3