Ok. This got me intrigued, and here is what I came up with:
---
- hosts: all
become: yes
tasks:
- name: Get path to php.ini
find:
paths: /etc/php
file_type: directory
recurse: no
register: ini_path
- name: Update php.ini post_max_size
replace:
dest: "{{ ini_path.files[0].path }}/apache2/php.ini"
regexp: '^post_max_size.*$'
replace: 'post_max_size = 20M'
backup: yes
- name: Update php.ini upload_max_filesize
replace:
dest: "{{ ini_path.files[0].path }}/apache2/php.ini"
regexp: '^upload_max_filesize.*$'
replace: 'upload_max_filesize = 20M'
backup: yes
The first thing I do is use the find module to determine which version of php we are running, and of course registering that result into ini_path. This works because the only directory under /etc/php is the directory with the actual version number:
ls /etc/php/
7.2
Since the registered result is a python dictionary, I later combine the result with the complete path to php_ini:
"{{ ini_path.files[0].path }}/apache2/php.ini"
This way we can use the playbook despite not knowing beforehand which version of php we are running (within reason, we have to use apache2!).
Execution against my test server (Ubuntu 18) looks like this:
ansible-playbook update_phpini.yml -i "192.168.1.11," -kK
SSH password:
SUDO password[defaults to SSH password]:
PLAY [all] *********************************************************************
TASK [setup] *******************************************************************
ok: [192.168.1.11]
TASK [Get path to php.ini] *****************************************************
ok: [192.168.1.11]
TASK [Update php.ini post_max_size] ********************************************
ok: [192.168.1.11]
TASK [Update php.ini upload_max_filesize] **************************************
ok: [192.168.1.11]
PLAY RECAP *********************************************************************
192.168.1.11 : ok=4 changed=0 unreachable=0 failed=0
In a production environment, you could do more test, and use set_fact to assign the path to a variable early on. This is just a POC.
Also, of course adjust the file sizes to your liking!!!