> ...
> - name: Replace string in files
> replace:
> dest: "{{ item.path }}"
> regexp: 'AMSPORT'
> replace: '{{AMSPORT}}'
> loop_control:
> label: "{{ item.path }}"
> with_items: "{{ files_to_change.files }}"
>
> ... all files replacing all variables.
In this case, the best option is the "nested" loop
https://docs.ansible.com/ansible/latest/plugins/lookup/nested.html#nested-composes-a-list-with-nested-elements-of-other-lists
Two lists are needed. A list of the files and a list of the
variables. Instead of the list of hashes it would be easier to use a
dictionary
my_vars:
MACHINE:
gpack.tmt.com
AMSPORT: 9933
The output of the task below shows how to create the loop
and the parameters
- debug:
msg:
- "dest: {{ item.0.path }}"
- "regexp: {{ item.1 }}"
- "replace: {{ my_vars[item.1] }}"
with_nested:
- "{{ files_to_change.files }}"
- "{{ my_vars.keys()|list }}"
If this is what you want replace the variables in the files
- name: Replace string in files
replace:
dest: "{{ item.0.path }}"
regexp: "{{ item.1 }}"
replace: "{{ my_vars[item.1] }}"
with_nested:
- "{{ files_to_change.files }}"
- "{{ my_vars.keys()|list }}"
--
Vladimir Botka