hass/tasks/main.yml

108 lines
3.6 KiB
YAML
Raw Normal View History

2020-01-29 20:56:37 +00:00
---
# tasks file for hass
- name: "Ensure database is present"
become: yes
mysql_db:
name: "{{ hass_db_name }}"
collation: utf8mb4_unicode_ci
encoding: utf8mb4
state: present
register: hass_database_creation
- name: import DATA in database in case of creation
become: yes
mysql_db:
name: "{{ hass_db_name }}"
state: import
target: "{{ hass_SQl_target_file }}"
when: hass_database_creation.changed == true and hass_SQl_target_file is defined
- name: "Ensure db user is present"
become: yes
mysql_user:
name: "{{ hass_db_user }}"
host: localhost
password: "{{ hass_db_password }}"
priv: "{{ hass_db_name }}.*:ALL"
state: present
- name: install HASS
pacman:
state: present # not required. choices: absent;latest;present. Desired state of the package.
name: "{{hass_pacman_name}}" # not required. Name or list of names of the packages to install, upgrade, or remove.
become: yes
2020-02-02 11:45:38 +00:00
- name: add {{user.name}} to hass group
user:
name: "{{ item }}"
groups: docker
append: true
with_items: "{{ hass_user }}"
2020-01-29 20:56:37 +00:00
- name: check repo
2020-01-30 19:29:46 +00:00
become: yes
stat:
path: "{{hass_conf_folder}}/.git" # required. The full path of the file/object to get the facts of.
2020-01-29 20:56:37 +00:00
register: hass_repo_exist
- name: clean conf folder if repo not exist
become: yes
file:
path: "{{hass_conf_folder}}"
state: absent
2020-01-30 19:29:46 +00:00
when: hass_repo_exist.stat.exists == false
2020-01-29 20:56:37 +00:00
- name: recreate conf folder
become: yes
file:
path: "{{hass_conf_folder}}"
state: directory
owner: "{{user.name}}"
2020-01-30 19:29:46 +00:00
when: hass_repo_exist.stat.exists == false
2020-01-29 20:56:37 +00:00
- name: install conf file
git:
dest: "{{hass_conf_folder}}" # required. The path of where the repository should be checked out. This parameter is required, unless C(clone) is set to C(no).
repo: "{{hass_repo}}" # required. git, SSH, or HTTP(S) protocol address of the git repository.
clone: yes # not required. If C(no), do not clone the repository if it does not exist locally
version: "{{hass_repo_branch}}"
notify: restart hass
2020-01-30 19:29:46 +00:00
when: hass_repo_exist.stat.exists == false
2020-01-29 20:56:37 +00:00
- name: change owner
become: yes
file:
state: directory
dest: "{{hass_conf_folder}}"
owner: hass
group: hass
recurse: yes
- name: copy failtoban config
template:
src: fail2ban/hass.local.j2
dest: /etc/fail2ban/jail.d/hass.local
notify: restart fail2ban
become: yes
2020-01-30 19:29:46 +00:00
- name: create cron for hass
2020-01-29 20:56:37 +00:00
cron:
2020-01-30 19:29:46 +00:00
job: "sh {{hass_conf_folder}}/backup_git.sh"
2020-01-29 20:56:37 +00:00
user: root # not required. The specific user whose crontab should be modified.
2020-01-30 19:29:46 +00:00
minute: "0" # not required. Minute when the job should run ( 0-59, *, */2, etc )
hour: "3"
2020-01-29 20:56:37 +00:00
name: "auto commit HASS config" # not required. Description of a crontab entry or, if env is set, the name of environment variable. Required if state=absent. Note that if name is not set and state=present, then a new crontab entry will always be created, regardless of existing ones.
become: yes
- name: enable HASS
service:
name: home-assistant # required. Name of the service.
enabled: true # not required. Whether the service should start on boot. B(At least one of state and enabled are required.)
state: started # not required. choices: reloaded;restarted;started;stopped. C(started)/C(stopped) are idempotent actions that will not run commands unless necessary. C(restarted) will always bounce the service. C(reloaded) will always reload. B(At least one of state and enabled are required.) Note that reloaded will start the service if it is not already started, even if your chosen init system wouldn't normally.
become: yes