In ansible, I'd like to replace this:
pgsql:
useCluster: false
addr: 127.0.0.1:5432
password: ""
email:
to: [email protected]
port: 465
password: ""
replace to this:
pgsql:
useCluster: false
addr: 127.0.0.1:5432
password: "2024xxx"
email:
to: [email protected]
port: 465
password: ""
Because there are two identical variables that cannot be replaced,I use this method.But it cannot be achieved. How should everyone handle it?
replace:
path: "config.yaml"
regexp: '(redis:[^<]*)password: ""'
replace: '\1password: "2024xxx"'
Use template Ansible module instead of replace.
Manually edit the source document to have Jinja expressions where the values should be.
Where
thing
is a short prefix for your organization or project, making names less likely to collide. And the variable name is from some secret storage lookup, given it is a password. default filter at the end is optional, depending on if you want a value if the variable is not defined, or an error.template module is different in that it has to render the source file on localhost, the Ansible controller. If you previously relied on the remote host containing values in this file, you may want to adjust to the managed host not being the source of truth anymore.