-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add new role * feat: update role heavily * ci: run linters in role directories * chore: add changelog fragment * ci: remove obsolete .gitignore * feat: check if systemd svc needs a restart * feat: switch to using a handler
- Loading branch information
Showing
16 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.cache | ||
.idea | ||
.vscode | ||
|
||
bellackn-homelab-*.tar.gz | ||
tests/output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
release_summary: |- | ||
Add hms_mqtt_publisher role |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ name: homelab | |
version: 5.0.1 | ||
readme: README.md | ||
authors: | ||
- Nico Bellack <[email protected]> | ||
- Nico Bellack <[email protected]> | ||
description: Holds various utils that are handy for a homelab infrastructure setup. | ||
license: | ||
- MIT | ||
|
@@ -13,6 +13,8 @@ tags: | |
- lxc | ||
- proxmox | ||
- tools | ||
- mqtt | ||
- hms | ||
repository: https://github.com/bellackn/ansible-collection-homelab | ||
documentation: https://github.com/bellackn/ansible-collection-homelab | ||
homepage: https://github.com/bellackn/ansible-collection-homelab | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
bellackn.hms-mqtt-publisher | ||
=========================== | ||
|
||
This role deploys a compiled binary of the [hms-mqtt-publisher][1] to a host. It | ||
conveniently sets it up as a systemd daemon. | ||
|
||
How to Use | ||
---------- | ||
|
||
1. Compile the binary for the wanted architecture using `cargo build`. | ||
2. Set `hms_mqtt_publisher_bin_path` to where you've put the compiled binary. | ||
3. Set the config variables for Home Assistant and/or simple MQTT publishing. | ||
4. Execute the role. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
See [defaults/main.yml](defaults/main.yml). | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
```yaml | ||
--- | ||
- name: Deploy MQTT publisher to Raspberry Pi | ||
hosts: pi | ||
gather_facts: true | ||
become: true | ||
vars: | ||
hms_mqtt_publisher_bin_path: /tmp/hms-mqtt-publish | ||
hms_mqtt_publisher_inverter_host: 192.168.1.2 | ||
hms_mqtt_publisher_homeassistant: | ||
host: homeassistant.local | ||
username: "{{ vault_hms_mqtt_publisher_homeassistant_username }}" | ||
password: "{{ vault_hms_mqtt_publisher_homeassistant_password }}" | ||
hms_mqtt_publisher_simple: | ||
host: mqtt.local | ||
collections: | ||
- bellackn.homelab | ||
roles: | ||
- hms_mqtt_publisher | ||
``` | ||
License | ||
------- | ||
MIT | ||
Author Information | ||
------------------ | ||
[Nico Bellack](mailto:[email protected]) | ||
[1]: https://github.com/DennisOSRM/hms-mqtt-publisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
# The method to use for installing the binary | ||
# TODO: For now, only 'local' is supported | ||
hms_mqtt_publisher_install_method: local | ||
|
||
# Path to the compiled binary (used for "local" method) | ||
hms_mqtt_publisher_bin_path: /tmp/hms-mqtt-publish | ||
|
||
# The directory into which all necessary files will be deployed | ||
hms_mqtt_publisher_basedir: /opt/hms-mqtt-publisher | ||
|
||
# The user who runs the systemd service | ||
hms_mqtt_publisher_svc_user: root | ||
hms_mqtt_publisher_svc_group: root | ||
|
||
# Inverter host | ||
hms_mqtt_publisher_inverter_host: "" | ||
|
||
# Update interval | ||
hms_mqtt_publisher_update_interval: 30500 | ||
|
||
# Home Assistant config | ||
hms_mqtt_publisher_homeassistant: {} | ||
# host: | ||
# port: | ||
# username: | ||
# password: | ||
|
||
# Simple MQTT config: | ||
hms_mqtt_publisher_simple: {} | ||
# host: | ||
# port: | ||
# username: | ||
# password: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Enable and (re-)start systemd service | ||
ansible.builtin.systemd: | ||
name: hms-mqtt-publish | ||
state: restarted | ||
enabled: true | ||
daemon_reload: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
galaxy_info: | ||
role_name: hms_mqtt_publisher | ||
namespace: bellackn | ||
author: Nico Bellack | ||
description: Deploys the hms-mqtt-publisher as systemd service | ||
license: MIT | ||
min_ansible_version: '2.9' | ||
galaxy_tags: | ||
- hms | ||
- mqtt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
- name: Create base directory | ||
ansible.builtin.file: | ||
path: "{{ hms_mqtt_publisher_basedir }}" | ||
state: directory | ||
owner: "{{ hms_mqtt_publisher_svc_user }}" | ||
group: "{{ hms_mqtt_publisher_svc_group }}" | ||
mode: "0774" | ||
|
||
# TODO: Mirror the compiled binaries somewhere online/add 'url/mirror' method | ||
- name: Copy binary to host | ||
ansible.builtin.copy: | ||
src: "{{ hms_mqtt_publisher_bin_path }}" | ||
dest: "{{ hms_mqtt_publisher_basedir }}/hms-mqtt-publish" | ||
owner: "{{ hms_mqtt_publisher_svc_user }}" | ||
group: "{{ hms_mqtt_publisher_svc_group }}" | ||
mode: "0774" | ||
notify: | ||
- Enable and (re-)start systemd service | ||
when: hms_mqtt_publisher_install_method == "local" | ||
|
||
- name: Copy config to host | ||
ansible.builtin.template: | ||
src: config.toml.j2 | ||
dest: "{{ hms_mqtt_publisher_basedir }}/config.toml" | ||
owner: "{{ hms_mqtt_publisher_svc_user }}" | ||
group: "{{ hms_mqtt_publisher_svc_group }}" | ||
mode: "0600" | ||
notify: | ||
- Enable and (re-)start systemd service | ||
|
||
- name: Deploy systemd service file | ||
ansible.builtin.template: | ||
src: hms-mqtt-publish.service.j2 | ||
dest: /etc/systemd/system/hms-mqtt-publish.service | ||
owner: "{{ hms_mqtt_publisher_svc_user }}" | ||
group: "{{ hms_mqtt_publisher_svc_group }}" | ||
mode: "0644" | ||
notify: | ||
- Enable and (re-)start systemd service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
inverter_host = "{{ hms_mqtt_publisher_inverter_host }}" | ||
update_interval = {{ hms_mqtt_publisher_update_interval }} | ||
|
||
{% if hms_mqtt_publisher_homeassistant %} | ||
[home_assistant] | ||
host = "{{ hms_mqtt_publisher_homeassistant.host }}" | ||
port = {{ hms_mqtt_publisher_homeassistant.port | default('1883')}} | ||
username = "{{ hms_mqtt_publisher_homeassistant.username | default('') }}" | ||
password = "{{ hms_mqtt_publisher_homeassistant.password | default('') }}" | ||
{% endif %} | ||
|
||
{% if hms_mqtt_publisher_simple %} | ||
[simple_mqtt] | ||
host = "{{ hms_mqtt_publisher_simple.host }}" | ||
port = {{ hms_mqtt_publisher_simple.port | default('1883') }} | ||
username = "{{ hms_mqtt_publisher_simple.username | default('') }}" | ||
password = "{{ hms_mqtt_publisher_simple.password | default('') }}" | ||
{% endif %} |
14 changes: 14 additions & 0 deletions
14
roles/hms_mqtt_publisher/templates/hms-mqtt-publish.service.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=HMS MQTT Publisher (cf. GitHub: DennisOSRM/hms-mqtt-publisher) | ||
After=multi-user.target | ||
|
||
[Service] | ||
ExecStart={{ hms_mqtt_publisher_basedir }}/hms-mqtt-publish | ||
WorkingDirectory={{ hms_mqtt_publisher_basedir }} | ||
Restart=on-failure | ||
Type=exec | ||
User={{ hms_mqtt_publisher_svc_user }} | ||
Group={{ hms_mqtt_publisher_svc_group }} | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[test] | ||
localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
roles: [] | ||
collections: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Test role syntax | ||
hosts: test | ||
roles: | ||
- hms_mqtt_publisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,7 @@ MIT | |
Author Information | ||
------------------ | ||
|
||
[Nico Bellack](mailto:[email protected]) | ||
[Nico Bellack](mailto:[email protected]) | ||
|
||
Acknowledgements | ||
---------------- | ||
|