Add esphome role and playbook

This commit is contained in:
yuri 2022-12-04 20:11:39 +01:00
parent 75408d8926
commit e084462ae1
No known key found for this signature in database
GPG key ID: E646779AC54AEC64
9 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,4 @@
esphome__version: "2022.11.4"
nginx__configs:
- name: esphome
content: "{{ lookup('ansible.builtin.file', 'configs/esphome/nginx/esphome.conf') }}"

View file

@ -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

View file

@ -0,0 +1,7 @@
---
- name: Deploy esphome on esphome.z9
become: true
hosts: esphome
roles:
- esphome
- nginx

View file

@ -0,0 +1,8 @@
server {
listen 80;
server_name esphome.z9;
location / {
proxy_pass http://localhost:6052;
}
}

View 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

View file

@ -0,0 +1,4 @@
- name: Restart esphome
ansible.builtin.systemd:
service: esphome.service
state: restarted

View file

@ -0,0 +1,8 @@
---
argument_specs:
main:
options:
esphome__version:
description: ESPHome version that should be installed.
type: str
required: true

View file

@ -0,0 +1,8 @@
---
dependencies:
- role: distribution_check
vars:
distribution_check__supported_distributions:
- name: Debian
versions:
- "11"

View 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