ansible/playbooks/install_mqtt_srv.yml

131 lines
4.2 KiB
YAML
Raw Normal View History

2024-11-29 01:37:55 +01:00
- hosts: datacenter
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-11-19 23:36:39 +01:00
vars:
2024-11-21 00:35:52 +01:00
dest_folder: "/share/Public/ans_repo1"
2024-06-08 22:23:49 +02:00
tasks:
2024-10-12 23:42:49 +02:00
# - name: Install python3-pip
# ansible.builtin.apt:
# name:
# - python3-pip
# update_cache: yes
2024-07-09 00:58:19 +02:00
2024-10-12 23:42:49 +02:00
# when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
# become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
2024-11-19 23:36:39 +01:00
- name: include vault
ansible.builtin.include_vars:
file: ../jaydee.yml
- name: GIT pull
2024-11-21 00:35:52 +01:00
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-11-19 23:36:39 +01:00
tags:
- git_pull
git:
2024-11-24 16:00:12 +01:00
repo: "https://{{ git_user | urlencode }}:{{ git_password_mqtt | urlencode }}@gitlab.sectorq.eu/jaydee/mqtt_srv.git"
2024-11-19 23:36:39 +01:00
dest: "{{ dest_folder }}"
update: yes
clone: yes
version: main
2024-11-19 07:53:39 +01:00
- debug:
msg: "{{ inventory_hostname }}"
2024-07-07 22:41:10 +02:00
2024-06-08 22:23:49 +02:00
- name: Upload service config
ansible.builtin.copy:
2024-11-19 23:36:39 +01:00
src: "{{ dest_folder }}/mqtt_srv.service"
2024-06-08 22:23:49 +02:00
dest: /etc/systemd/system/
2024-11-19 07:53:39 +01:00
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' 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:
2024-11-19 23:36:39 +01:00
src: "{{ dest_folder }}/mqtt_srv.py"
2024-06-08 22:23:49 +02:00
dest: /usr/bin/
2024-06-08 22:31:52 +02:00
mode: '755'
2024-06-08 22:34:41 +02:00
owner: root
2024-11-19 07:53:39 +01:00
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-11-19 07:56:57 +01:00
2024-10-30 12:14:02 +01:00
- name: Upload service script config
ansible.builtin.copy:
2024-11-19 23:36:39 +01:00
src: "{{ dest_folder }}/mqtt_srv.cfg"
2024-10-30 12:17:23 +01:00
dest: /etc/mqtt_srv/
2024-10-30 12:14:02 +01:00
mode: '755'
owner: root
2024-11-19 07:53:39 +01:00
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-11-19 07:29:48 +01:00
# - name: Upload service script1
# ansible.builtin.copy:
# src: scripts/mqtt_srv.sh
# dest: /jffs/scripts/mqtt_srv/
# mode: '755'
# owner: admin
# 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'
# owner: admin
# when: inventory_hostname in groups['router']
# become: false
2024-07-09 00:21:30 +02:00
2024-07-08 22:39:36 +02:00
- name: Upload service script1
ansible.builtin.copy:
2024-11-19 23:36:39 +01:00
src: "{{ dest_folder }}/mqtt_srv.sh"
2024-07-08 22:39:36 +02:00
dest: /etc/init.d/
mode: '755'
owner: admin
2024-11-21 00:35:52 +01:00
remote_src: true
2024-11-19 07:56:57 +01:00
when: inventory_hostname == 'nas.home.lan'
2024-11-19 07:53:39 +01:00
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-11-21 00:35:52 +01:00
- debug:
msg: "{{ dest_folder }}"
2024-07-08 22:39:36 +02:00
- name: Upload service script2
2024-07-07 22:41:10 +02:00
ansible.builtin.copy:
2024-11-19 23:36:39 +01:00
src: "{{ dest_folder }}/mqtt_srv.py"
2024-11-21 00:35:52 +01:00
dest: /usr/bin/mqtt_srv.py
2024-07-07 22:41:10 +02:00
mode: '755'
owner: admin
2024-11-21 00:35:52 +01:00
remote_src: true
when: inventory_hostname == 'nas.home.lan'
2024-11-19 07:53:39 +01:00
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-07-07 22:41:10 +02:00
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-11-19 07:53:39 +01:00
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' 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-11-19 07:53:39 +01:00
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' 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-11-19 07:53:39 +01:00
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-07-07 22:41:10 +02:00
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-11-21 00:35:52 +01:00
when: inventory_hostname == 'nas.home.lan'
2024-11-19 07:53:39 +01:00
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
2024-07-07 22:46:28 +02:00