On Sun, 6 Sep 2020 21:03:24 -0700 (PDT)
Abdulrazzaq shaik <[email protected]> wrote:

> vars:
>     - MACHINE: gpack.tmt.com
>     - AMSPORT: 9933
> ...
>     - 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

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200907075057.54c4450a%40gmail.com.

Attachment: pgp94FFTcdF3I.pgp
Description: OpenPGP digital signature

Reply via email to