ansible/playbooks/install_mqtt_srv.yml
2024-07-07 22:45:09 +02:00

70 lines
2.3 KiB
YAML

- hosts: datacenter
name: Install mqtt_srv
ignore_unreachable: false
tasks:
- name: Install bottle python package
ansible.builtin.apt:
name:
- python3-pip
when: inventory_hostname not in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Upload service config
ansible.builtin.copy:
src: services/mqtt_srv.service
dest: /etc/systemd/system/
when: inventory_hostname not in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Upload service script
ansible.builtin.copy:
src: scripts/mqtt_srv.py
dest: /usr/bin/
mode: '755'
owner: root
when: inventory_hostname not in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Upload service script
ansible.builtin.copy:
src: scripts/mqtt_srv.py
dest: /share/Data/__GITLAB/mqtt_srv/
mode: '755'
owner: admin
when: inventory_hostname in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Install bottle python package
ansible.builtin.shell: pip install {{ item }} --break-system-packages
loop:
- paho-mqtt
- getmac
- ping3
- psutil
- autorandr
when: inventory_hostname not in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Just force systemd to reread configs (2.4 and above)
ansible.builtin.systemd:
daemon_reload: true
when: inventory_hostname not in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Restart mqtt_srv service
ansible.builtin.service:
name: mqtt_srv.service
state: restarted
when: inventory_hostname not in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: Install bottle python package
ansible.builtin.shell: "/share/ZFS530_DATA/.qpkg/QPython312/bin/python3 /share/Data/__GITLAB/mqtt_srv/mqtt_srv.py > /dev/null 2>&1 &"
when: inventory_hostname in groups['nas']
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"