URAMIRAIKAN

1020のなれの果て (since 2005.6.19)

MariaDB 10.3から10.4へのアップグレード

 MariaDB 10.4が出てから結構時間が経ってしまいましたが、ようやくここのサイトのデータベースをアップグレードしました。
 基本的には10.3へアップグレードしたときと同じなのですけどね。

 ただ、同じ事をやるのもつまらないので、今回はその手順をAnsibleで実行しました。
 使ったPlaybookはこんな感じ。

--- - name: MariaDB Upgrade hosts: localhost remote_user: operator become: yes gather_facts: yes vars: temp_dir: /tmp/maria-upd db_admin: root db_pwd: password tasks: - name: Create temp directory file: path: '{{ temp_dir }}' state: directory owner: root group: root mode: 0755 - name: Backup MariaDB current configuration shell: \cp -pf /etc/my.cnf {{ temp_dir }}/ - name: Backup MariaDB current configuration shell: \cp -prf /etc/my.cnf.d {{ temp_dir }}/ - name: Backup Postfix current configuration shell: \cp -prf /etc/postfix {{ temp_dir }}/ - name: Backup fail2ban current configuration shell: \cp -prf /etc/fail2ban {{ temp_dir }}/ - name: Update all packages yum: name: '*' state: latest - name: Stop services systemd: name: '{{ item }}' state: stopped daemon_reload: no enabled: no with_items: - mariadb.service - postfix.service - fail2ban.service - name: Remove old MariaDB packages yum: name: - MariaDB-* - galera state: absent - name: Replace MariaDB repository copy: src: ./files/MariaDB.repo dest: /etc/yum.repos.d/MariaDB.repo owner: root group: root mode: 0644 - name: Install new packages yum: name: - MariaDB-server - MariaDB-client - MariaDB-backup - postfix - fail2ban state: latest - name: Restore MariaDB configuration shell: \cp -pf {{ temp_dir }}/my.cnf /etc/ - name: Restore MariaDB configuration shell: \cp -prf {{ temp_dir }}/my.cnf.d /etc/ - name: Start MariaDB services systemd: name: mariadb.service state: started daemon_reload: yes enabled: yes - name: Upgrade databases shell: mysql_upgrade -u{{ db_admin }} -p{{ db_pwd }} - name: Restore Postfix configraion shell: \cp -prf {{ temp_dir }}/postfix /etc/ - name: Start postfix services systemd: name: postfix.service state: started daemon_reload: yes enabled: yes - name: Restore fail2ban configuration shell: \cp -prf {{ temp_dir }}/fail2ban /etc/ - name: Start fail2ban services systemd: name: fail2ban.service state: started daemon_reload: yes enabled: yes - name: Delete temp directory file: path: '{{ temp_dir }}' state: absent

 実際にはリモートで実行しているから"hosts"や"remote_user"とかは変更しています。
 あと、使っている"MariaDB.repo"はMariaDBのサイトで生成したものを用意。
 相変わらずうちの環境では"postfix"と"fail2ban"が依存性でアンインストールされてしまうので、作業前に設定ファイルを待避して後で戻しています。

 それはそうとして、とりあえず時間も手間もかけずに手順を置き換えただけなので冪等性とか考慮してないし、"shell"モジュールばかりであまり良いものではないですね。
 ちょっと時間があるときにでも、よりAnsible的なPlaybookに修正しようかと思います。