Skip to content

Instantly share code, notes, and snippets.

@MartinZikmund
Created March 14, 2023 19:29
Show Gist options
  • Save MartinZikmund/c74a8708653c247d0f9715da6ee6cdca to your computer and use it in GitHub Desktop.
Save MartinZikmund/c74a8708653c247d0f9715da6ee6cdca to your computer and use it in GitHub Desktop.
To create an Ansible playbook that installs MySQL 5.7 on Ubuntu 22.04 Live Server, follow these steps:
Install Ansible on your control machine.
Create an inventory file (e.g., hosts.ini) that lists the target server(s). Replace the server_ip and ansible_user with the appropriate values for your target server:
csharp
Copy code
[mysql_servers]
server_ip ansible_user=your_user
Create a new file called install_mysql57.yml and add the following content:
yaml
Copy code
---
- name: Install MySQL 5.7 on Ubuntu 22.04
hosts: mysql_servers
become: yes
tasks:
- name: Update apt cache
ansible.builtin.apt:
update_cache: yes
cache_valid_time: 3600
- name: Install software-properties-common
ansible.builtin.apt:
name: software-properties-common
state: present
- name: Add MySQL APT repository
ansible.builtin.apt_repository:
repo: 'deb http://repo.mysql.com/apt/ubuntu/ focal mysql-5.7'
state: present
update_cache: yes
- name: Install MySQL APT GPG key
ansible.builtin.apt_key:
url: 'https://repo.mysql.com/RPM-GPG-KEY-mysql'
state: present
- name: Install MySQL Server 5.7
ansible.builtin.apt:
name: mysql-server
state: present
force_apt_get: yes
- name: Start and enable MySQL service
ansible.builtin.systemd:
name: mysql
state: started
enabled: yes
This playbook does the following:
Updates the apt cache.
Installs the software-properties-common package to manage repositories.
Adds the MySQL APT repository for Ubuntu 20.04 (Focal Fossa) to install MySQL 5.7 on Ubuntu 22.04.
Installs the MySQL APT GPG key.
Installs the MySQL Server 5.7.
Starts and enables the MySQL service.
Run the playbook using the following command:
bash
Copy code
ansible-playbook -i hosts.ini install_mysql57.yml --ask-become-pass
This command will prompt you for the sudo password of the target server.
Please note that MySQL 5.7 is not officially supported on Ubuntu 22.04. The playbook above uses the MySQL APT repository for Ubuntu 20.04 (Focal Fossa) to install MySQL 5.7 on Ubuntu 22.04. It's recommended to use MySQL 8.0, which is the version officially supported on Ubuntu 22.04, or consider using an alternative like MariaDB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment