I’m trying to setup playbook that will setup some docker services. I’m trying to pass some variables that are obtained by vars_prompt to docker-compose file.
replace:
path: files/docker-compose.yaml
regexp: 'SERVER_IP'
replace: '{{ ip_address }}'
Destination file
environment:
(...)
SERVER_IP: 'SERVICE_IP_ADDR'
(...)
Right now such task replace whole line with ip_address variable
expected result
environment:
(...)
SERVER_IP: ip_address
(...)
2
Answers
After some test I've found solution for that.
Instead of the modules replace or lineinfile, a more robust solution would be updating the dictionary. For example, given the file
and the below variables
declare the dictionary dc_update
Include the content of the file into the dictionary dc
and declare the below variable
This gives the updated configuration
Writes the updated configuration into the file
Running the play with the
--diff
options givesNotes:
SERVER_IP
, the valueSERVICE_IP_ADDR
, or both. All options below give the same result