diff --git a/roles/services/handlers/main.yaml b/roles/services/handlers/main.yaml index a0077b4..3785321 100644 --- a/roles/services/handlers/main.yaml +++ b/roles/services/handlers/main.yaml @@ -24,3 +24,9 @@ name: spacestated state: restarted daemon_reload: true + +- name: restart mastodon-spacestate + systemd: + name: mastodon-spacestate + state: restarted + daemon_reload: true diff --git a/roles/services/tasks/main.yaml b/roles/services/tasks/main.yaml index 11b0285..62bc122 100644 --- a/roles/services/tasks/main.yaml +++ b/roles/services/tasks/main.yaml @@ -10,3 +10,6 @@ - tags: services_spacestated import_tasks: spacestated.yaml + +- tags: services_mastodon_spacestate + import_tasks: mastodon_spacestate.yaml diff --git a/roles/services/tasks/mastodon_spacestate.yaml b/roles/services/tasks/mastodon_spacestate.yaml new file mode 100644 index 0000000..b9883dd --- /dev/null +++ b/roles/services/tasks/mastodon_spacestate.yaml @@ -0,0 +1,39 @@ +--- +- name: Install dependencies + apt: + name: + - python3-mastodon + - python3-paho-mqtt + +- name: Clone source + git: + repo: https://github.com/bitlair/mastodon-spacestate.git + version: main + dest: /var/lib/mastodon-spacestate + accept_hostkey: yes + notify: restart mastodon-spacestate + +- name: Install config + template: + src: mastodon-spacestate-config.py + dest: /var/lib/mastodon-spacestate/config.py + owner: root + group: root + mode: 0655 + notify: restart mastodon-spacestate + +- name: Install service file + template: + src: mastodon-spacestate.service + dest: /etc/systemd/system/mastodon-spacestate.service + owner: root + group: root + mode: 0644 + notify: restart mastodon-spacestate + +- name: Start mastodon-spacestate + systemd: + name: mastodon-spacestate + state: started + enabled: yes + daemon_reload: true diff --git a/roles/services/tasks/spacestated.yaml b/roles/services/tasks/spacestated.yaml index 0a77caa..7cf0146 100644 --- a/roles/services/tasks/spacestated.yaml +++ b/roles/services/tasks/spacestated.yaml @@ -19,6 +19,7 @@ version: main dest: /var/lib/spacestated/spacestated accept_hostkey: yes + notify: restart spacestated - name: Install service file template: diff --git a/roles/services/templates/mastodon-spacestate-config.py b/roles/services/templates/mastodon-spacestate-config.py new file mode 100644 index 0000000..fe30c15 --- /dev/null +++ b/roles/services/templates/mastodon-spacestate-config.py @@ -0,0 +1,14 @@ +mqtt_server = 'mqtt.bitlair.nl' +mqtt_port = 1883 + +spacestate_topic = 'bitlair/state' +open_string = 'open' +closed_string = 'closed' + +spacestate_profile_key = 'Spacestate' +open_profile_field = 'Open! @ {}' +closed_profile_field = 'Closed @ {}' + +profile_fields = [('Website', 'https://bitlair.nl/')] +access_token = '{{ mastodon_spacestate_access_token }}' +homeserver = 'https://hsnl.social' diff --git a/roles/services/templates/mastodon-spacestate.service b/roles/services/templates/mastodon-spacestate.service new file mode 100644 index 0000000..4e7e458 --- /dev/null +++ b/roles/services/templates/mastodon-spacestate.service @@ -0,0 +1,15 @@ +# Managed by Ansible + +[Unit] +Description=Bitlair Spacestate propagation to Mastodon +After=network.target + +[Service] +Type=simple +Restart=on-failure +RestartSec=10s +ExecStart=/var/lib/mastodon-spacestate/mastodon-spacestate.py +DynamicUser=true + +[Install] +WantedBy=multi-user.target