2020-10-02 16:51:05 +02:00
|
|
|
---
|
|
|
|
- name: Get actual Mysql password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: "grep password {{ nextcloud_home }}/.my.cnf | awk '{ print $3 }'"
|
2020-10-02 16:51:05 +02:00
|
|
|
register: nextcloud_db_pass_grep
|
|
|
|
check_mode: no
|
|
|
|
changed_when: False
|
|
|
|
failed_when: False
|
|
|
|
tags:
|
|
|
|
- nextcloud
|
|
|
|
|
|
|
|
- name: Generate Mysql password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: 'apg -n 1 -m 16 -M lcN'
|
2020-10-02 16:51:05 +02:00
|
|
|
register: nextcloud_db_pass_apg
|
|
|
|
check_mode: no
|
|
|
|
changed_when: False
|
|
|
|
tags:
|
|
|
|
- nextcloud
|
|
|
|
|
|
|
|
- name: Set Mysql password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.set_fact:
|
2020-10-02 16:51:05 +02:00
|
|
|
nextcloud_db_pass: "{{ nextcloud_db_pass_grep.stdout | default(nextcloud_db_pass_apg.stdout, True) }}"
|
|
|
|
tags:
|
|
|
|
- nextcloud
|
|
|
|
|
2023-03-20 23:33:19 +01:00
|
|
|
- ansible.builtin.debug:
|
2020-10-02 16:51:05 +02:00
|
|
|
var: nextcloud_db_pass
|
|
|
|
verbosity: 1
|
|
|
|
|
|
|
|
- name: Create Mysql database
|
2023-03-20 23:33:19 +01:00
|
|
|
community.mysql.mysql_db:
|
2020-10-02 16:51:05 +02:00
|
|
|
name: "{{ nextcloud_db_name }}"
|
|
|
|
config_file: "/root/.my.cnf"
|
|
|
|
state: present
|
|
|
|
tags:
|
|
|
|
- nextcloud
|
|
|
|
|
|
|
|
- name: Create Mysql user
|
2023-03-20 23:33:19 +01:00
|
|
|
community.mysql.mysql_user:
|
2020-10-02 16:51:05 +02:00
|
|
|
name: "{{ nextcloud_db_user }}"
|
|
|
|
password: '{{ nextcloud_db_pass }}'
|
|
|
|
priv: "{{ nextcloud_db_name }}.*:ALL"
|
|
|
|
config_file: "/root/.my.cnf"
|
|
|
|
update_password: always
|
|
|
|
state: present
|
|
|
|
tags:
|
|
|
|
- nextcloud
|
|
|
|
|
|
|
|
- name: Store credentials in my.cnf
|
2023-03-20 23:33:19 +01:00
|
|
|
community.general.ini_file:
|
2020-10-02 16:51:05 +02:00
|
|
|
dest: "{{ nextcloud_home }}/.my.cnf"
|
|
|
|
owner: "{{ nextcloud_user }}"
|
|
|
|
group: "{{ nextcloud_user }}"
|
|
|
|
mode: "0600"
|
|
|
|
section: client
|
|
|
|
option: "{{ item.option }}"
|
|
|
|
value: "{{ item.value }}"
|
2021-05-04 14:18:40 +02:00
|
|
|
loop:
|
2020-10-02 16:51:05 +02:00
|
|
|
- { option: "user", value: "{{ nextcloud_db_user }}" }
|
|
|
|
- { option: "database", value: "{{ nextcloud_db_name }}" }
|
|
|
|
- { option: "password", value: "{{ nextcloud_db_pass }}" }
|
|
|
|
tags:
|
|
|
|
- nextcloud
|