2024-06-08 22:23:49 +02:00
|
|
|
- hosts: datacenter
|
|
|
|
name: Install mqtt_srv
|
|
|
|
ignore_unreachable: false
|
|
|
|
tasks:
|
2024-06-27 00:19:16 +02:00
|
|
|
- name: Install bottle python package
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name:
|
|
|
|
- python3-pip
|
2024-07-07 22:32:10 +02:00
|
|
|
when: inventory_hostname not in groups['nas']
|
2024-07-07 22:37:22 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
2024-07-07 22:41:10 +02:00
|
|
|
|
|
|
|
|
2024-06-08 22:23:49 +02:00
|
|
|
- name: Upload service config
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: services/mqtt_srv.service
|
|
|
|
dest: /etc/systemd/system/
|
2024-07-07 22:32:10 +02:00
|
|
|
when: inventory_hostname not in groups['nas']
|
2024-07-07 22:37:22 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
2024-07-07 22:41:10 +02:00
|
|
|
|
|
|
|
|
2024-06-08 22:23:49 +02:00
|
|
|
- name: Upload service script
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: scripts/mqtt_srv.py
|
|
|
|
dest: /usr/bin/
|
2024-06-08 22:31:52 +02:00
|
|
|
mode: '755'
|
2024-06-08 22:34:41 +02:00
|
|
|
owner: root
|
2024-07-07 22:32:10 +02:00
|
|
|
when: inventory_hostname not in groups['nas']
|
2024-07-07 22:37:22 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
2024-07-07 22:41:10 +02:00
|
|
|
|
2024-07-08 22:39:36 +02:00
|
|
|
- name: Upload service script1
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: scripts/mqtt_srv.sh
|
|
|
|
dest: /etc/init.d/
|
|
|
|
mode: '755'
|
|
|
|
owner: admin
|
|
|
|
when: inventory_hostname in groups['nas']
|
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
|
|
|
|
|
|
|
- name: Upload service script2
|
2024-07-07 22:41:10 +02:00
|
|
|
ansible.builtin.copy:
|
|
|
|
src: scripts/mqtt_srv.py
|
2024-07-08 22:39:36 +02:00
|
|
|
dest: /usr/bin/
|
2024-07-07 22:41:10 +02:00
|
|
|
mode: '755'
|
|
|
|
owner: admin
|
|
|
|
when: inventory_hostname in groups['nas']
|
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
|
|
|
|
2024-06-08 22:34:41 +02:00
|
|
|
- name: Install bottle python package
|
2024-06-27 00:19:16 +02:00
|
|
|
ansible.builtin.shell: pip install {{ item }} --break-system-packages
|
|
|
|
loop:
|
|
|
|
- paho-mqtt
|
|
|
|
- getmac
|
|
|
|
- ping3
|
|
|
|
- psutil
|
|
|
|
- autorandr
|
2024-07-07 22:32:10 +02:00
|
|
|
when: inventory_hostname not in groups['nas']
|
2024-07-07 22:37:22 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
2024-07-07 22:41:10 +02:00
|
|
|
|
|
|
|
|
2024-06-08 23:47:29 +02:00
|
|
|
- name: Just force systemd to reread configs (2.4 and above)
|
|
|
|
ansible.builtin.systemd:
|
|
|
|
daemon_reload: true
|
2024-07-07 22:32:10 +02:00
|
|
|
when: inventory_hostname not in groups['nas']
|
2024-07-07 22:37:22 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
2024-07-07 22:41:10 +02:00
|
|
|
|
|
|
|
|
2024-06-08 23:47:29 +02:00
|
|
|
- name: Restart mqtt_srv service
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: mqtt_srv.service
|
2024-07-07 22:32:10 +02:00
|
|
|
state: restarted
|
2024-07-07 22:37:22 +02:00
|
|
|
when: inventory_hostname not in groups['nas']
|
2024-07-07 22:41:10 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
|
|
|
|
2024-07-07 23:08:16 +02:00
|
|
|
- name: Install bottle python package1
|
2024-07-08 22:39:36 +02:00
|
|
|
ansible.builtin.shell: "(/etc/init.d/mqtt_srv.sh restart >/dev/null 2>&1 &)"
|
2024-07-07 23:18:55 +02:00
|
|
|
async: 10
|
|
|
|
poll: 0
|
2024-07-07 22:43:04 +02:00
|
|
|
when: inventory_hostname in groups['nas']
|
2024-07-07 22:41:10 +02:00
|
|
|
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
|
|
|
|
|
2024-07-07 22:46:28 +02:00
|
|
|
|
|
|
|
|
2024-07-07 22:41:10 +02:00
|
|
|
|