Hey community, need your help again…
On my goal of automation I’m blocked on loops… dont know if I’m doing wrong, need to change approach or if just stupid…
Well, lets try…
I would like to replace lines in FILES_A with lines that are on MAPPING_A.
`
- name: Add values from MAPPING_A to FILES_A
lineinfile:
path: “/PATH_TO/FILES_A/{{ item.0 | basename }}”
line: “{{ item.1 }}”
insertafter: “^(.*){{ item.1.split(‘=’) | first }}”
with_nested: - “{{ lookup(‘fileglob’, ‘/PATH_TO/MAPPING_A/*.TXT’) }}”
- “{{ lookup(‘file’, ‘/PATH_TO/MAPPING_A/{{ item.0 | basename }}.TXT’).splitlines() | select() | list }}”
`
Allow me to give more insight of what I want to achieve with that loop:
`
“{{ lookup(‘fileglob’, ‘/PATH_TO/MAPPING_A/*.TXT’) }}”
`
^^ want to list all files on that folder, because I will need to collect filename - thats the reason why i have “**{{ item.0 | basename }}” at path - that would be what I use to identify which files I want to change.
If files exists in that folder will contain content to replace on a diferent destination and filename is what I’m using. If filename exists on both sides will collect content and insert it.
so that will be the first loop
`
“{{ lookup(‘file’, ‘/PATH_TO/MAPPING_A/{{ item.0 | basename }}.TXT’).splitlines() | select() | list }}”
`
^^ Ok, after the first loop is in place (list of which files to edit), now on the second loop I need to per file to read content in order to replace on the destination.
What is happening?
Maybe its not supposed to… Ansible is not recognizing “{{ item.0 | basename }}” at second loop…
Well… ¯_(ツ)_/¯ again… I’m stuck, can anyone share thoughts/suggestions with me?