Let me add a quick update : 
- I'm trying to process several paths 
- paths are grouped and so, there are several "list" of paths (because need 
to generate from template and it's different regarding the list)
- objective was to use an compact / easier code (instead of copy existing 
task for a new list, just use kind of "function" ... = include and loop)




Le mercredi 22 avril 2020 18:07:32 UTC+2, Laurent HENSSEN a écrit :
>
> Hello, 
>
>
> I'm trying to register a var through a dynamical use of "register" (I mean 
> : using a var, like : register: {{ var }}).
>
> Dev updated the code and removed this option (now static only).
> I'm not able to find more information about that change and also there is 
> nobody connected on the IRC so, I post here.
>
>
> Bug report (closed without real details) : 
> https://github.com/ansible/ansible/issues/57839
>
> Code change : 
>
> https://gitlab.ics.muni.cz/242618/ansible/commit/be776daefed047f0bd45d7441efde046677fd417
>
>
> The very detailed comment about that (from the bug report) : 
> ---
> sivel <https://github.com/sivel> commented on Jun 14, 2019 
> <https://github.com/ansible/ansible/issues/57839#issuecomment-502115371>
>
> This is expected and we will never allow this behavior. Register must use 
> a statically defined string.
>
> If you have further questions please stop by IRC or the mailing list:
>
>    - IRC: #ansible on irc.freenode.net
>    - mailing list: https://groups.google.com/forum/#!forum/ansible-project
>
> [image: @sivel] <https://github.com/sivel> sivel 
> <https://github.com/sivel> closed this on Jun 14, 2019 
> <https://github.com/ansible/ansible/issues/57839#event-2413731177>
> ---
>
>
> That's it, no more information, I don't understand why and now I'm stuck 
> in my Ansible configuration.
> I was trying to create a loop of 4 tasks (function like), I'm able to pass 
> any vars to those tasks (using separated include: and loop:).
> But all this is useless if I can't register results in "dynamically 
> selected" variable name.
> Final results are input for a template (just after that include task).
>
> So, I have now a "working" function, able to consume any var already 
> defined ... but can only register to a unique var (very very useful when 
> you are in a loop with MULTIPLE elements and not only 1).
> Can someone explain me why this change of behavior and how am I supposed 
> to make it works now without the option to "register: {{ my_var }} ?
>
> Let me copy past my configuration so that it will be easier to understand.
> What I see with that change to static register : can't loop on tasks 
> anymore (or only for basic use).
> Pelase let me know how I'm supposed to do that in "a compact way" now (I 
> was trying to move from 5x blocks of 4 tasks to 1 include (with loop) of 4 
> tasks).
>
>
> ---
> (main)
> # Check if paths exist + extract real path (no symlink) 
> ######################################################################################
> # Using a Function like in Ansible (= big loop on included tasks)
> - include: path_checker.yml
>   loop_control:
>     # As we are creating a big loop, and as we also have one nested loop, 
> need to use another var name else they conflict (if "item" on both nested 
> loops)
>     loop_var: path_list
>   # Here, need to add all lists available so that all paths will be 
> checked as expected (before generating the template)
>   loop:
>     - audit_list_include_power_abuse
>     - audit_list_exclude_network_accept
>     - audit_list_exclude_network_socket
>     - audit_list_include_power_abuse
>     - audit_list_exe_exclude_all
>     - audit_list_dir_exclude_all
>
> (path_checker)
> # 1. Path exists ?
> - name: check if excluded paths exist (list={{ path_list }})
>   stat:
>     path: "{{ item }}"
>   register: "{{ path_list }}_result_exist"
>   #register: audit_list_include_power_abuse_result_exist
> #  debug:
> #    msg: "HIHI : {{ item }}"
>   loop: "{{ vars[path_list] }}"
>
> [...]
>
> (error)
>  [WARNING]: "register" is not templatable, but we found: {{ path_list 
> }}_result_exist, it will not be templated and will be used "as is".
> ---
>
>
> How should I do now to avoid all my duplicated blocks ? 
>
>
> Thanks, 
> Laurent
>

-- 
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/2be7f256-8b1d-4079-9b91-0c128a54b0c3%40googlegroups.com.

Reply via email to