From ecd2f7aa6125d13ec746fb8397dad59519918f8d Mon Sep 17 00:00:00 2001 From: marito Date: Mon, 16 Jun 2025 16:52:20 +0800 Subject: [PATCH] phpmyadmin as utility --- Lenvi.yaml | 9 +++++- playbook.yml | 2 ++ roles/phpmyadmin/tasks/main.yml | 57 +++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 roles/phpmyadmin/tasks/main.yml diff --git a/Lenvi.yaml b/Lenvi.yaml index 40d0487..dca1022 100644 --- a/Lenvi.yaml +++ b/Lenvi.yaml @@ -2,8 +2,15 @@ # Lenvi: Central Configuration for Your Development Environment # ------------------------------------------------------------------ +# Optional developer utilities +utilities: + phpmyadmin: + enabled: true + domain: "pma.lenvi.local" # Or whatever you prefer + php_version: "8.2" + # 1. Set the global database engine. -db_engine: "mariadb" +db_engine: "mariadb" # mariadb, mysql or postgresql # 2. Define the global database credentials. db_credentials: diff --git a/playbook.yml b/playbook.yml index bf33c9e..d11b403 100644 --- a/playbook.yml +++ b/playbook.yml @@ -17,4 +17,6 @@ - role: php - role: composer - role: nginx + - role: phpmyadmin + when: utilities.phpmyadmin.enabled is defined and utilities.phpmyadmin.enabled - role: projects \ No newline at end of file diff --git a/roles/phpmyadmin/tasks/main.yml b/roles/phpmyadmin/tasks/main.yml new file mode 100644 index 0000000..7bf7667 --- /dev/null +++ b/roles/phpmyadmin/tasks/main.yml @@ -0,0 +1,57 @@ +--- +- name: Define Apache packages to manage + ansible.builtin.set_fact: + apache_packages: + - apache2 + - apache2-bin + - apache2-data + - apache2-utils + +# This block runs when phpmyadmin is enabled +- name: "Enable phpMyAdmin" + when: utilities.phpmyadmin.enabled | default(false) + block: + - name: "Place a 'hold' on Apache packages to prevent installation" + ansible.builtin.dpkg_selections: + name: "{{ item }}" + selection: hold + loop: "{{ apache_packages }}" + + - name: "Install phpMyAdmin from APT repository" + ansible.builtin.apt: + name: phpmyadmin + state: present + update_cache: yes + + - name: "Create Nginx config for phpMyAdmin using the main project template" + ansible.builtin.template: + src: ../projects/templates/nginx-site.conf.j2 + dest: "/etc/nginx/conf.d/{{ utilities.phpmyadmin.domain }}.conf" + vars: + project: + domain: "{{ utilities.phpmyadmin.domain }}" + document_root: "/usr/share/phpmyadmin" + php_version: "{{ utilities.phpmyadmin.php_version }}" + notify: Reload Nginx + +# This block runs when phpmyadmin is disabled or not defined +- name: "Disable phpMyAdmin" + when: not (utilities.phpmyadmin.enabled | default(false)) + block: + - name: "Remove the Nginx config for phpMyAdmin" + ansible.builtin.file: + path: "/etc/nginx/conf.d/{{ utilities.phpmyadmin.domain }}.conf" + state: absent + notify: Reload Nginx + + - name: "Remove the phpMyAdmin package" + ansible.builtin.apt: + name: phpmyadmin + state: absent + autoremove: yes + + - name: "Release the 'hold' on Apache packages" + ansible.builtin.dpkg_selections: + name: "{{ item }}" + selection: install + loop: "{{ apache_packages }}" \ No newline at end of file