ansible/playbooks/install_mqtt_srv.yml
ladislav.dusa 4b0810a7f3 conf added
2024-11-24 16:00:12 +01:00

129 lines
4.0 KiB
YAML

- hosts: mqtt_srv
name: Install mqtt_srv
ignore_unreachable: false
ignore_errors: true
vars:
dest_folder: "/tmp/ans_repo"
tasks:
# - name: Install python3-pip
# ansible.builtin.apt:
# name:
# - python3-pip
# update_cache: yes
# when: inventory_hostname not in groups['nas'] and inventory_hostname not in groups['router']
# become: "{{ 'no' if inventory_hostname in groups['nas'] else 'yes' }}"
- name: include vault
ansible.builtin.include_vars:
file: ../jaydee.yml
- name: GIT pull
become: true
tags:
- git_pull
git:
repo: "https://{{ git_user | urlencode }}:{{ git_password_mqtt | urlencode }}@gitlab.sectorq.eu/jaydee/mqtt_srv.git"
dest: "{{ dest_folder }}"
update: yes
clone: yes
version: main
- debug:
msg: "{{ inventory_hostname }}"
- name: Upload service config
ansible.builtin.copy:
src: "{{ dest_folder }}/mqtt_srv.service"
dest: /etc/systemd/system/
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
- name: Upload service script
ansible.builtin.copy:
src: "{{ dest_folder }}/mqtt_srv.py"
dest: /usr/bin/
mode: '755'
owner: root
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
- name: Upload service script config
ansible.builtin.copy:
src: "{{ dest_folder }}/mqtt_srv.cfg"
dest: /etc/mqtt_srv/
mode: '755'
owner: root
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
# - 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
- name: Upload service script1
ansible.builtin.copy:
src: "{{ dest_folder }}/mqtt_srv.sh"
dest: /etc/init.d/
mode: '755'
owner: admin
when: inventory_hostname == 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
- name: Upload service script2
ansible.builtin.copy:
src: "{{ dest_folder }}/mqtt_srv.py"
dest: /usr/bin/
mode: '755'
owner: admin
when: inventory_hostname == 'router.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' 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 != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
- name: Just force systemd to reread configs (2.4 and above)
ansible.builtin.systemd:
daemon_reload: true
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
- name: Restart mqtt_srv service
ansible.builtin.service:
name: mqtt_srv.service
state: restarted
enabled: true
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"
- name: Restart mqtt service
ansible.builtin.shell: "(/etc/init.d/mqtt_srv.sh restart >/dev/null 2>&1 &)"
async: 10
poll: 0
when: inventory_hostname != 'nas.home.lan'
become: "{{ 'no' if inventory_hostname == 'nas.home.lan' else 'yes' }}"