hass/tasks/main.yml
2020-01-29 21:56:37 +01:00

108 lines
3.4 KiB
YAML

---
# 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
#- name: add {{user.name}} to hass group
# user:
# name: "{{ item }}"
# groups: docker
# append: true
# with_items: "{{ hass_user }}"
- name: check repo
git:
repo: "{{hass_repo}}"
dest: "{{hass_conf_folder}}"
clone: no
update: no
register: hass_repo_exist
- name: clean conf folder if repo not exist
become: yes
file:
path: "{{hass_conf_folder}}"
state: absent
- name: recreate conf folder
become: yes
file:
path: "{{hass_conf_folder}}"
state: directory
owner: "{{user.name}}"
- 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
- 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
- name: create cron for dyndns
cron:
job: "sh {{{{hass_conf_folder}}/backup_git.sh"
user: root # not required. The specific user whose crontab should be modified.
minute: 00 03 * * * # not required. Minute when the job should run ( 0-59, *, */2, etc )
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