ansible/playbooks/install_mqtt_srv.yml

113 lines
3.6 KiB
YAML
Raw Normal View History

2024-07-09 00:50:55 +02:00
- hosts: mqtt_srv
2024-06-08 22:23:49 +02:00
name: Install mqtt_srv
2024-07-09 02:05:42 +02:00
ignore_unreachable: false
2024-07-09 01:51:42 +02:00
ignore_errors: true
2024-06-08 22:23:49 +02:00
tasks:
2024-07-09 00:27:36 +02:00
- name: Install python3-pip
2024-06-27 00:19:16 +02:00
ansible.builtin.apt:
name:
- python3-pip
2024-07-09 00:58:19 +02:00
update_cache: yes
2024-07-09 00:29:35 +02:00
when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
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-09 00:32:15 +02:00
when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
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-09 00:21:30 +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-09 00:32:15 +02:00
when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
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-09 00:21:30 +02:00
- name: Upload service script1
ansible.builtin.copy:
src: scripts/mqtt_srv.sh
dest: /jffs/scripts/mqtt_srv/
mode: '755'
2024-07-09 00:34:45 +02:00
owner: admin
2024-07-09 00:21:30 +02:00
when: inventory_hostname in groups['router']
become: false
- name: Upload service script
ansible.builtin.copy:
src: scripts/mqtt_srv.py
dest: /jffs/scripts/mqtt_srv/
mode: '755'
2024-07-09 00:34:45 +02:00
owner: admin
2024-07-09 00:32:15 +02:00
when: inventory_hostname in groups['router']
2024-07-09 00:21:30 +02:00
become: false
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-09 00:32:15 +02:00
when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
2024-07-09 01:00:33 +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-09 00:32:15 +02:00
when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
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-09-20 14:56:09 +02:00
enabled: true
2024-07-09 00:32:15 +02:00
when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
2024-07-07 22:41:10 +02:00
become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
2024-07-08 22:58:17 +02:00
- name: Restart mqtt service
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-09 00:25:29 +02:00
2024-07-09 00:21:30 +02:00
- name: Restart mqtt service
ansible.builtin.shell: "(/jffs/scripts/mqtt_srv/mqtt_srv.sh restart >/dev/null 2>&1 &)"
async: 10
poll: 0
when: inventory_hostname in groups['router']
become: false
2024-07-07 22:46:28 +02:00
2024-07-07 22:41:10 +02:00