Add esphome role and playbook
This commit is contained in:
parent
75408d8926
commit
e084462ae1
4
inventories/thinkcccentre/host_vars/esphome.yml
Normal file
4
inventories/thinkcccentre/host_vars/esphome.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
esphome__version: "2022.11.4"
|
||||||
|
nginx__configs:
|
||||||
|
- name: esphome
|
||||||
|
content: "{{ lookup('ansible.builtin.file', 'configs/esphome/nginx/esphome.conf') }}"
|
|
@ -6,3 +6,5 @@ all:
|
||||||
ansible_host: light.z9
|
ansible_host: light.z9
|
||||||
automation:
|
automation:
|
||||||
ansible_host: automation.z9
|
ansible_host: automation.z9
|
||||||
|
esphome:
|
||||||
|
ansible_host: esphome.z9
|
||||||
|
|
7
playbooks/deploy_esphome.yml
Normal file
7
playbooks/deploy_esphome.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
- name: Deploy esphome on esphome.z9
|
||||||
|
become: true
|
||||||
|
hosts: esphome
|
||||||
|
roles:
|
||||||
|
- esphome
|
||||||
|
- nginx
|
8
playbooks/files/configs/esphome/nginx/esphome.conf
Normal file
8
playbooks/files/configs/esphome/nginx/esphome.conf
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name esphome.z9;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:6052;
|
||||||
|
}
|
||||||
|
}
|
10
playbooks/roles/esphome/files/esphome.service
Normal file
10
playbooks/roles/esphome/files/esphome.service
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=ESPHome
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/home/esphome/.local/bin/esphome dashboard config/
|
||||||
|
WorkingDirectory=/home/esphome/.local/bin
|
||||||
|
User=esphome
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
4
playbooks/roles/esphome/handlers/main.yml
Normal file
4
playbooks/roles/esphome/handlers/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
- name: Restart esphome
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
service: esphome.service
|
||||||
|
state: restarted
|
8
playbooks/roles/esphome/meta/argument_specs.yml
Normal file
8
playbooks/roles/esphome/meta/argument_specs.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
argument_specs:
|
||||||
|
main:
|
||||||
|
options:
|
||||||
|
esphome__version:
|
||||||
|
description: ESPHome version that should be installed.
|
||||||
|
type: str
|
||||||
|
required: true
|
8
playbooks/roles/esphome/meta/main.yml
Normal file
8
playbooks/roles/esphome/meta/main.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
dependencies:
|
||||||
|
- role: distribution_check
|
||||||
|
vars:
|
||||||
|
distribution_check__supported_distributions:
|
||||||
|
- name: Debian
|
||||||
|
versions:
|
||||||
|
- "11"
|
33
playbooks/roles/esphome/tasks/main.yml
Normal file
33
playbooks/roles/esphome/tasks/main.yml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
- name: Ensure acl is installed
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: acl
|
||||||
|
- name: Ensure pip is installed
|
||||||
|
ansible.builtin.apt:
|
||||||
|
name: python3-pip
|
||||||
|
- name: Ensure esphome user exists
|
||||||
|
ansible.builtin.user:
|
||||||
|
name: esphome
|
||||||
|
- name: Ensure esphome dependencies are installed
|
||||||
|
become_user: esphome
|
||||||
|
ansible.builtin.pip:
|
||||||
|
name: tornado
|
||||||
|
extra_args: --user
|
||||||
|
- name: Ensure esphome are installed
|
||||||
|
become_user: esphome
|
||||||
|
ansible.builtin.pip:
|
||||||
|
name: "esphome=={{ esphome__version }}"
|
||||||
|
extra_args: --user
|
||||||
|
notify: Restart esphome
|
||||||
|
- name: Ensure esphome systemd service file is deployed
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: esphome.service
|
||||||
|
dest: /etc/systemd/system/esphome.service
|
||||||
|
mode: 0644
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
notify: Restart esphome
|
||||||
|
- name: Ensure esphome service is enabled and started
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
service: esphome.service
|
||||||
|
enabled: true
|
||||||
|
state: started
|
Loading…
Reference in a new issue