--- - 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 }}"