-
  name: "Block to Allow Loading of Variables without running task"
  when: run_tasks
  block:
    -
      name: "Installing MariaDB"
      ansible.builtin.apt:
        name:
          - mariadb-server
    
    -
      name: "Starting MariaDB"
      ansible.builtin.systemd:
        name: mariadb
        state: started
    
    -
      name: "Sets the password for {{ mariadb_admin_user }}"
      become: true
      community.mysql.mysql_user:
        user: "{{ mariadb_admin_user }}"
        password: "{{ mariadb_admin_pass }}"
        host: localhost
      register: set_password_result
      failed_when:
        - set_password_result.failed
        - "'ERROR' in set_password_result.msg"
    
    -
      name: "Securing MariaDB"
      become: true
      ansible.builtin.expect:
        command: mysql_secure_installation
        responses:
          'Enter current password for root \(enter for none\): ': ''
          'Switch to unix_socket authentication \[Y\/n\] ': 'n'
          'Change the root password\? \[Y\/n\] ': 'y'
          'New password:': "{{ mariadb_admin_pass }}"
          'Re-enter new password:': "{{ mariadb_admin_pass }}"
          'Remove anonymous users\? \[Y\/n\]': 'y'
          'Disallow root login remotely\? \[Y\/n\]': 'n'
          'Remove test database and access to it\? \[Y\/n\]': 'y'
          'Reload privilege tables now\? \[Y\/n\]': 'y'
    
    -
      name: "Configuring MariaDB to bind to all ports"
      ansible.builtin.lineinfile:
        mode: "0755"
        path: "{{ item.dir }}"
        regexp: "^bind-address"
        create: true
        line: "bind-address  = 0.0.0.0"
      with_items:
        - { dir: "/etc/mysql/mariadb.conf.d/50-server.cnf" }
    
    -
      name: "Restarting MariaDB"
      ansible.builtin.systemd:
        name: mariadb
        state: restarted
    