As much as I like them I would recommend against grep/cat/awk in this
case as it makes things very fragile.
Instead try to use something that PHP and ansible can both use - such as JSON.
For example my WordPress has:
define('DB_PASSWORD',
'(U>Trob!t]J=-APTjNr[b9()yL#-95r8[3s4MpM~S0dI=`Pb7td9$):M{kENu|i323');
This playbook then gets that password:
tasks:
- name: JSON encode constants
command: php -r 'require_once("wp-config.php");
echo json_encode(get_defined_constants(true)["user"]);'
register: php_out
- set_fact:
php_constants: "{{ php_out.stdout | from_json }}"
- debug: var=php_constants.DB_PASSWORD
TASK [debug] ***************************************************************************************************************************************
ok: [wp] =>
php_constants.DB_PASSWORD:
(U>Trob!t]J=-APTjNr[b9()yL#-95r8[3s4MpM~S0dI=`Pb7td9$):M{kENu|i323
DIck
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
ansible-proje...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/acbd9abb-8f6d-4847-8d46-7d87fa1d15b6%40googlegroups.com.
--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT