Re: [ansible-project] [ Ansible ] - Weird nested loop help

2020-02-24 Thread Jean-Yves LENHOF

Not so obvious to understand...

Perhaps you should try progressive steps and not wanting to do 
everything in one unique step


To look for specific file, perhaps you should use the find module with a 
register


And after loop on these files using the variable registered before...

Regards,


Le 24/02/2020 à 14:00, João Santos a écrit :

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.



Screenshot 2020-02-24 at 12.55.04.png




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?

--
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 ansible-project+unsubscr...@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e9220677-c1a0-4d7f-bf07-336e62ec1be7%40googlegroups.com 
.


--
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6302aa8a-ff56-c217-9ddf-e389456bea1f%40lenhof.eu.org.


Re: [ansible-project] [ Ansible ] - Weird nested loop help

2020-02-24 Thread João Santos
Hey thanks for your comment regarding automation, it's very useful.

Might not make sense to you and that's the reason why I explained with
details - was to explain what I'm trying to achieve, what I'm trying but
without success and with expectations that someone could share more than
you had done.



Thanks again.



On Mon, 24 Feb 2020 at 14:01, Stefan Hornburg (Racke) 
wrote:

> On 2/24/20 2:00 PM, João Santos wrote:
> > 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...
> >
>
> You don't show no evidence of what are you trying to automate :-(.
>
> At any rate it doesn't make sense to use "item" inside the loop definition.
>
> Regards
> Racke
>
> > 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.
> >
> >
> > Screenshot 2020-02-24 at 12.55.04.png
> >
> >
> >
> >
> > 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?
> >
> > --
> > 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
> > ansible-project+unsubscr...@googlegroups.com  ansible-project+unsubscr...@googlegroups.com>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/e9220677-c1a0-4d7f-bf07-336e62ec1be7%40googlegroups.com
> > <
> https://groups.google.com/d/msgid/ansible-project/e9220677-c1a0-4d7f-bf07-336e62ec1be7%40googlegroups.com?utm_medium=email_source=footer
> >.
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7ac2d9e8-bf14-b854-954f-736e8e389c0a%40linuxia.de
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAG3v9hcw21mhACrYLHVVOFrHbe_Wx%2BaXM2PbZU87ZAAsT402%2Bg%40mail.gmail.com.


Re: [ansible-project] [ Ansible ] - Weird nested loop help

2020-02-24 Thread Stefan Hornburg (Racke)
On 2/24/20 2:00 PM, João Santos wrote:
> 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...
> 

You don't show no evidence of what are you trying to automate :-(.

At any rate it doesn't make sense to use "item" inside the loop definition.

Regards
Racke

> 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.
> 
> 
> Screenshot 2020-02-24 at 12.55.04.png
> 
> 
> 
> 
> 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?
> 
> -- 
> 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
> ansible-project+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/e9220677-c1a0-4d7f-bf07-336e62ec1be7%40googlegroups.com
> .


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7ac2d9e8-bf14-b854-954f-736e8e389c0a%40linuxia.de.


signature.asc
Description: OpenPGP digital signature