On Wed, 27 Sep 2017 07:30:54 -0700 (PDT) jean-christophe manciot <[email protected]> wrote:
> hello guys, > I need to build filenames based on 3 parts: basename, version and > trailing '.x86_64.rpm'. > Let's focus on the first 2 parts: > The first one is: > "installed_mtx_packages_name": [ > "mtx-device", > "mtx-grpc-agent", > "mtx-infra", > ... > ] > > The second one is: > "installed_mtx_packages_version": [ > "1.0.0-r1705191346", > "1.0.1-r1705191346", > "1.0.0-r1705170158", > ... > ] > > the goal is to obtain this: > "installed_mtx_packages_partialname": [ > "mtx-device-1.0.0-r1705191346", > "mtx-grpc-agent-1.0.0-r1705191346", Should this line be "mtx-grpc-agent-1.0.1-r1705191346" by any chance? Just checking if the example might be a typo :) > "mtx-infra-1.0.0-r1705170158", > ... > ] This is not an answer for your question, but maybe a nudge to rethink it if possible - do you absolutely have to form these as two separate lists? Where do the installed_mtx_packages_name and installed_mtx_packages_version variables come from? Command, some external file? Otherwise, you may want to look at this (if I understood your requirements well): https://docs.ansible.com/ansible/latest/playbooks_loops.html#looping-over-parallel-sets-of-data > I've tried several strategies, including: > - name: Building partial name of installed MTX packages > set_fact: > installed_mtx_packages_partialname: > "{{ installed_mtx_packages_name | map('regex_replace', '(.*)', > '\\1-item') | list }}" with_items: installed_mtx_packages_version > > But of course the item is considered as a string here instead of a > variable. > > If I move the ' just before item, I get the error: > "template error while templating string: expected token ',', got > 'string' " Not 100% sure what you mean by "just before item", but I'm assuming you'd want (e.g. note the "'\\1-' + item" part - you can concatenate strings this way): "{{ installed_mtx_packages_name | map('regex_replace', '(.*)', '\\1-' + item) | list }}" Additionally, you should switch to using (I think without moustaches this would iterate over an item literal "installed_mtx_packages_version" otherwise): with_items: "{{ installed_mtx_packages_version }}" To top it off - I'm pretty sure this particular loop would not produce the list you desire. Best regards -- Branko Majic XMPP: [email protected] Please use only Free formats when sending attachments to me. Бранко Мајић XMPP: [email protected] Молим вас да додатке шаљете искључиво у слободним форматима. -- 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 post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/20170927175634.40cfe506%40majic.rs. For more options, visit https://groups.google.com/d/optout.
