If you’re going to generate something using a config management system; why not just template config.php itself?
jinja templating in Salt is my preference. Ansible should be the same.
e.g.
[~/SRC/salt/file_root/observium]$ cat init.sls | grep ^observium_config_file -A 10
observium_config_file:
file.managed:
- name: /etc/observium/config.php
- user: root
- group: root
- mode: 0644
- source: salt://observium/files/config.php
- template: jinja
- require:
- file: observium_config_dir
[~/SRC/salt/file_root/observium]$ head files/config.php
<?php
// /etc/observium/config.php
// This file is managed by Salt Stack. Make changes to the state NOT this file.
// Database config
$config['db_host'] = '{{ salt['pillar.get']('observium:db:host', 'localhost') }}';
$config['db_user'] = '{{ salt['pillar.get']('observium:db:user', 'observium') }}';
$config['db_pass'] = '{{ salt['pillar.get']('observium:db:pass', 'FIX_ME') }}';
$config['db_name'] = '{{ salt['pillar.get']('observium:db:name', 'observium') }}';
$config['db_extension'] = 'mysqli';
[~/SRC/salt/file_root/observium]$