--- # 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 become: true user: name: "{{ item }}" groups: hass append: true with_items: "{{ hass_user }}" - name: check repo become: yes stat: path: "{{hass_conf_folder}}/.git" # required. The full path of the file/object to get the facts of. register: hass_repo_exist - name: clean conf folder if repo not exist become: yes file: path: "{{hass_conf_folder}}" state: absent when: hass_repo_exist.stat.exists == false - name: recreate conf folder become: yes file: path: "{{hass_conf_folder}}" state: directory owner: "{{user.name}}" when: hass_repo_exist.stat.exists == false - 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 become: true when: hass_repo_exist.stat.exists == false - 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 hass cron: job: "sh {{hass_conf_folder}}/backup_git.sh" user: root # not required. The specific user whose crontab should be modified. minute: "0" # not required. Minute when the job should run ( 0-59, *, */2, etc ) hour: "3" 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