I would need to extract an username and a password from a configuration file.
define( 'DB_USER', 'username' );
define( 'DB_PASSWORD', 'password' );
So far I managed to extract a string, using this code:
- set_fact:
dbuser: "{{ wpconfig.stdout | regex_search('DB_USER(.+)', '\\1') | first }}"
Output
ok: [prod_server] => {
"dbuser": "', 'username' );"
}
I would need to extract only the username
part and get rid of all other characters.
I tried to play a bit with regular expressions, and I managed to build up one that apparently extracts the username
part putting it into Group 1: https://regex101.com/r/OzJR1X/2
If I try to add it to my code, an error shows up:
Syntax Error while loading YAML.
found unknown escape character 's'