ctucx.git: ansible-configs

My personal ansible roles and playbooks [deprecated in favor of nixos]

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
---

- name: "Create specified MySQL databases"
  community.mysql.mysql_db:
    login_unix_socket: /run/mysqld/mysqld.sock
    state: "{{ item.state | default('present') }}"
    name: "{{ item.name }}"
  loop: "{{ query('list', services.mariadb.databases)[0] }}"
  when:
    - services.mariadb.databases is defined

- name: "Create specified Mysql-Users"
  community.mysql.mysql_user:
    login_unix_socket: /run/mysqld/mysqld.sock
    state: "{{ item.state | default('present') }}"
    name: "{{ item.username }}"
    password: "{{ item.password }}"
    priv: "{{ item.privileges }}"
  loop: "{{ query('list', services.mariadb.users)[0] }}"
  when:
    - services.mariadb.users is defined

- community.mysql.mysql_info:
    login_unix_socket: /run/mysqld/mysqld.sock
    filter:
      - databases
      - users
    return_empty_dbs: yes
  register: mysql_info
  when:
    - services.mariadb.databases is defined

- name: "Dump databases that are not meant to be deployed"
  community.mysql.mysql_db:
    login_unix_socket: /run/mysqld/mysqld.sock
    state: dump
    name: "{{ item }}"
    target: "/root/{{ item }}.sql"
  loop: "{{ mysql_info['databases'] | list }}"
  when:
    - services.mariadb.databases is defined
    - "item != 'mysql'"
    - "item != 'test'"
    - "item != 'information_schema'"
    - "item != 'performance_schema'"
    - "item not in (services.mariadb.databases | map(attribute='name') | list)"

- name: "Delete databases that are not meant to be deployed"
  community.mysql.mysql_db:
    login_unix_socket: /run/mysqld/mysqld.sock
    state: absent
    name: "{{ item }}"
  loop: "{{ mysql_info['databases'] | list }}"
  when:
    - services.mariadb.databases is defined
    - "item != 'mysql'"
    - "item != 'test'"
    - "item != 'information_schema'"
    - "item != 'performance_schema'"
    - "item not in (services.mariadb.databases | map(attribute='name') | list)"

- name: "Delete users that are not meant to be deployed"
  community.mysql.mysql_user:
    login_unix_socket: /run/mysqld/mysqld.sock
    state: absent
    user: "{{ item }}"
  loop: "{{ mysql_info['users']['localhost'] | list }}"
  when:
    - services.mariadb.databases is defined
    - "item != 'mysql'"
    - "item != 'mariadb.sys'"
    - "item != ''"
    - "item != 'root'"
    - "item not in (services.mariadb.users | map(attribute='username') | list)"