I have a PHP role that defines the versions of PHP to install and the FPM pools to configure and enable that looks something like this:
php_versions:
8.1:
state: present
pools:
admin:
state: present
listen: /run/php/admin_php-fpm.sock
www:
state: present
listen: /run/php/php8.1-fpm.sock
8.2:
state: present
pools:
www:
state: present
listen: /run/php/php8.2-fpm.sock
And for monitoring purposes I have realised that the PHP-FPM pool names need to be unique, there can’t be a www
pool for more than one version of PHP as there is currently.
What would be the best way to check that the pools
keys are unique when the PHP version state
is present
and the pool state
is present
across the PHP versions?
This role is going to have to delete some www
pools using a config like this:
php_versions:
8.1:
state: present
pools:
admin:
state: present
listen: /run/php/admin_php-fpm.sock
www:
state: absent
www81:
state: present
listen: /run/php/php8.1-fpm.sock
8.2:
state: present
pools:
www:
state: absent
www82:
state: present
listen: /run/php/php8.2-fpm.sock
I have got as far as a JMESPath query to generate lists of the pool names (using the first version of php_versions
above):
- name: Debug pool names
ansible.builtin.debug:
msg: "{{ php_versions | community.general.json_query('*.pools[].keys(@)') }}"
when: php_versions is defined
This returns:
ok: [php] => {
"msg": [
[
"www"
],
[
"admin",
"www"
]
]
}
I expect I could put something together using loops and include_tasks
but I was wondering if there would be a better way someone could suggest…
BTW I added the community
tag here assuming that it was a reference to the community.general
collection but perhaps it isn’t?