Skip to content
Snippets Groups Projects
Verified Commit a52b9200 authored by Chris Croome's avatar Chris Croome
Browse files

Add ability to remove packages

parent 7cc5c725
No related branches found
No related tags found
No related merge requests found
Pipeline #27204 passed
......@@ -44,12 +44,20 @@ A boolean, `mariadb_mysqltuner` defaults to `true` and results in [MySQLTuner](h
A version number for MySQLTuner, `mariadb_mysqltuner_version` defaults to `1.9.9` the version provided by [Debian Bookworm](https://packages.debian.org/bookworm/mysqltuner). If `mariadb_mysqltuner_version` is set to `latest` then the [versions available from GitHub](https://github.com/major/MySQLTuner-perl/releases) are checked and the latest release is installed.
### mariadb_pkgs
### mariadb_pkgs_absent
A list of Debian packages to install, the default value for `mariadb_pkgs`:
```yaml
mariadb_pkgs:
mariadb_pkgs_absent: []
```
### mariadb_pkgs_present
A list of Debian packages to install, the default value for `mariadb_pkgs`:
```yaml
mariadb_pkgs_present:
- git
- jo
- mariadb-client
......
......@@ -51,7 +51,8 @@ mariadb_config:
max_allowed_packet: "64M"
mariadb_mysqltuner: true
mariadb_mysqltuner_version: "1.9.9"
mariadb_pkgs:
mariadb_pkgs_absent: []
mariadb_pkgs_present:
- git
- jo
- mariadb-client
......
......@@ -89,11 +89,16 @@ argument_specs:
type: str
required: true
description: MySQLTuner version.
mariadb_pkgs:
mariadb_pkgs_absent:
type: list
elements: str
required: false
description: A list of packages to install.
description: A list of packages to remove if present.
mariadb_pkgs_present:
type: list
elements: str
required: false
description: A list of packages to install if absent.
mariadb_priv:
type: list
elements: str
......
......@@ -44,34 +44,52 @@
tags:
- mariadb_local_facts
- name: Install MariaDB packages
- name: Install and remove MariaDB packages
block:
- name: "{{ mariadb_task_name }}"
ansible.builtin.apt:
pkg: "{{ mariadb_pkgs }}"
pkg: "{{ mariadb_pkgs_present }}"
state: present
update_cache: false
vars:
mariadb_task_name: >-
Packages {% for mariadb_pkg in mariadb_pkgs | difference(ansible_local.dpkg.installed) %}{{ mariadb_pkg -}}
Packages {% for mariadb_pkg in mariadb_pkgs_present | ansible.builtin.difference(ansible_local.dpkg.installed) %}{{ mariadb_pkg -}}
{%- if loop.length > 1 and not loop.last %}, {% endif %}{% endfor %} and dependancies installed
register: mariadb_install
notify: Restart mariadb
- name: "{{ mariadb_task_name }}"
ansible.builtin.apt:
pkg: "{{ mariadb_pkgs }}"
state: present
update_cache: false
vars:
mariadb_task_name: >-
Packages {% for mariadb_pkg in mariadb_pkgs_absent | ansible.builtin.intersect(ansible_local.dpkg.installed) %}{{ mariadb_pkg -}}
{%- if loop.length > 1 and not loop.last %}, {% endif %}{% endfor %} removed
register: mariadb_remove
notify: Restart mariadb
- name: Include apt role local fact tasks # noqa: no-handler
ansible.builtin.include_role:
name: apt
tasks_from: local_facts.yml
when:
- mariadb_install.changed is defined
- mariadb_install.changed | bool
when:
- mariadb_pkgs is defined
- mariadb_pkgs != []
- ansible_local.dpkg.installed is defined
- mariadb_pkgs | difference(ansible_local.dpkg.installed) != []
when: >-
( ( mariadb_install.changed is defined ) and
( mariadb_install.changed | bool ) ) or
( ( mariadb_remove.changed is defined ) or
( mariadb_remove.changed | bool ) )
when: >
( ( mariadb_pkgs_present is defined ) and
( mariadb_pkgs_present != [] ) and
( ansible_local.dpkg.installed is defined ) and
( mariadb_pkgs_present | ansible.builtin.difference(ansible_local.dpkg.installed) != [] ) ) or
( ( mariadb_pkgs_absent is defined ) and
( mariadb_pkgs_absent != [] ) and
( ansible_local.dpkg.installed is defined ) and
( mariadb_pkgs_absent | ansible.builtin.intersect(ansible_local.dpkg.installed) != [] ) ) or
tags:
- mariadb_install
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment