postgress hass

This commit is contained in:
vincent 2020-09-08 21:05:11 +02:00
parent 265a7dfe84
commit c1d05ea9bc
4 changed files with 61 additions and 23 deletions

View File

@ -7,6 +7,7 @@ hass_python_package:
- myjdapi - myjdapi
hass_conf_folder: /var/lib/hass hass_conf_folder: /var/lib/hass
hass_venv_location: /opt/venv/hass hass_venv_location: /opt/venv/hass
hass_db_type: postgres #postgres or mysql
hass_db_name: hass hass_db_name: hass
hass_db_user: hass hass_db_user: hass
hass_SQl_target_file: / hass_SQl_target_file: /

27
tasks/database_mysql.yml Normal file
View File

@ -0,0 +1,27 @@
- 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

View File

@ -0,0 +1,29 @@
- name: "Ensure db user is present"
become: yes
become_user: postgres
postgresql_user:
name: "{{ hass_db_user }}"
password: "{{ hass_db_password }}"
state: present
- name: "Ensure database is present"
become: yes
become_user: postgres
postgresql_db:
name: "{{ hass_db_name }}"
lc_collate: fr_FR.UTF-8
encoding: utf8
owner: "{{ hass_db_user }}"
state: present
register: hass_database_creation
- name: import DATA in database in case of creation
become: yes
become_user: postgres
postgresql_db:
name: "{{ hass_db_name }}"
state: restore
target: "{{ hass_SQl_target_file }}"
register: hass_database_import
when: hass_database_creation.changed == true and hass_SQl_target_file is defined

View File

@ -1,32 +1,13 @@
--- ---
# tasks file for hass # 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 - name: select specific Database tasks
become: yes include_tasks: "database_{{hass_db_type}}.yml"
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: create hass user - name: create hass user
become: yes become: yes