Afin d'automatiser l'installation de MySQL sous Debian, Ansible est l'outils qu'il nous faut.
Le seul point délicat concerne l'installation du meta-packatage "mysql-server" qui se fait par défaut en mode intéractif.
Pour passer en mode non intéractif, on doit placer des commandes debconf dans le script ansible.
--- # Installation de MySQL 8.0 sous Debian - hosts: mysql vars: debian_name: buster mysql_version: 8.0 gpg_key_id: "A4A9406876FCBD3C456770C88C718D3B5072E1F5" source_directory: /root/playbooks/mysql_install_8.0 root_password: "@Root6789P@ssw0rd@" remote_user: root tasks: - name: install gnupg linux package apt: name: gnupg - name: copy GPG key file copy: src: "{{ source_directory }}/mysql_pubkey.asc" dest: /tmp/mysql_pubkey.asc - name: install key apt_key: id: "{{ gpg_key_id }}" file: /tmp/mysql_pubkey.asc state: present - name: copy apt repository file template: src: "{{ source_directory }}/mysql.list" dest: /etc/apt/sources.list.d/mysql.list - name: configure package installation ... root password debconf: name: mysql-community-server question: mysql-community-server/root-pass value: "{{ root_password }}" vtype: password - name: configure package installation ... confirm root password debconf: name: mysql-community-server question: mysql-community-server/re-root-pass value: "{{ root_password }}" vtype: password - name: configure package installation ... authentication method debconf: name: mysql-community-server question: mysql-server/default-auth-override value: Use Strong Password Encryption (RECOMMENDED) vtype: select - name: install mysql apt: name: mysql-server update_cache: yes environment: DEBIAN_FRONTEND: noninteractive
-----BEGIN PGP PUBLIC KEY BLOCK----- Version: SKS 1.1.6 Comment: Hostname: pgp.mit.edu mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3RODjQRey CITRrdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZfw2vOUgCmYv2hW0h yDHuvYlQA/BThQoADgj8AW6/0Lo7V1W9/8VuHP0gQwCgvzV3BqOxRznNCRCRxAuAuVztHRcE ... W4XsWgCePBYaHBWL34WbYHlFm+mj74EGR0+IVAQYEQIADAUCPj6jHQUJCWYBgAASCRCMcY07 UHLh9QdlR1BHAAEB7p4An3r1QpVC9yhnW2cSAjq+kr72GX0eAJ4295kl6NxYEuFApmr1+0uU q/SlsYhUBBgRAgAMBQJOdz3tBQkT+wG4ABIHZUdQRwABAQkQjHGNO1By4fUUmwCbBYr2+bBE n/L2BOcnw9Z/QFWuhRMAoKVgCFm5fadQ3Afi+UQlAcOphrnJ =TkS6 -----END PGP PUBLIC KEY BLOCK-----
deb http://repo.mysql.com/apt/debian/ {{ debian_name }} mysql-{{ mysql_version }}
# ansible-playbook mysql_install_8.0.yml PLAY [mysql] ****************************************************************************************************************************************** TASK [Gathering Facts] ******************************************************************************************************************************** ok: [mysql03] TASK [install gnupg linux package] ******************************************************************************************************************** [WARNING]: Updating cache and auto-installing missing dependency: python-apt ok: [mysql03] TASK [copy GPG key file] ****************************************************************************************************************************** changed: [mysql03] TASK [install key] ************************************************************************************************************************************ changed: [mysql03] TASK [copy apt repository file] *********************************************************************************************************************** changed: [mysql03] TASK [configure package installation ... root password] *********************************************************************************************** changed: [mysql03] TASK [configure package installation ... confirm root password] *************************************************************************************** changed: [mysql03] TASK [configure package installation ... authentication method] *************************************************************************************** changed: [mysql03] TASK [install mysql] ********************************************************************************************************************************** changed: [mysql03] PLAY RECAP ******************************************************************************************************************************************** mysql03 : ok=9 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0