Whatever works is what counts.
    Thanks,
    -Mark


From: [email protected] <[email protected]> On 
Behalf Of Matthew Davis
Sent: Tuesday, May 7, 2019 5:26 PM
To: Ansible Project <[email protected]>
Subject: [ansible-project] Re: Create a variable that contains other variable 
values with labels

Here is a solution using regex and map. It's not the most computationally 
efficient, but it works.

---
- hosts: localhost
  tasks:
    - name: set first fact
      set_fact:
        list1:
          - value1
          - value2

    - name: set second fact
      set_fact:
        var1: "{{ list1 | map('regex_replace', '^(.*)$','label \\1<file://1>')  
| list }} "

    - name: print second fact
      debug:
        var: var1

Regards,
Matt


On Friday, May 3, 2019 at 3:00:45 AM UTC+10, Mark Tovey wrote:


    I have a list:

list1
    - value1
    - value2

    and I want to use set_fact create a new variable that contains these 
variables with a label in front of them, so that this debug task:

- debug:
msg:  "{{var1}}"

     would result in output that looks like this:

label value1
label value2

    This gives me the expected results:

- set_fact:
var1:  |+
"{{'label ' ~ list1[0]}}"
"{{'label ' ~ list1[1]}}"

    But I need more flexibility than that.  I need to be able to add or remove 
values to or from the list and not have to modify the set_fact task each time 
to accommodate the modification.  I tried using the join filter:

- set_fact:
var1:
"{{'label ' ~ list1 | join('\n')}}"

     And that got me:

label value1
value2

    Close, but not quite.  So what is the best method of achieving what I want?



--
You received this message because you are subscribed to a topic in the Google 
Groups "Ansible Project" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/ansible-project/lAKvHcdvCrw/unsubscribe<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Ftopic%2Fansible-project%2FlAKvHcdvCrw%2Funsubscribe&data=02%7C01%7Cmark.tovey%40dsv.com%7Ce9260521e8e247ed5a3e08d6d34bdc0b%7C4a90c23a3ece4ef2b857522f23b8204c%7C0%7C0%7C636928720097890069&sdata=7MSyONbwoOOZYKqKl2MoZgRnMAWA6XgW2oZzkQAkip8%3D&reserved=0>.
To unsubscribe from this group and all its topics, send an email to 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3f8bb125-1b2c-4961-b04c-2cc39e6827d4%40googlegroups.com<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F3f8bb125-1b2c-4961-b04c-2cc39e6827d4%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=02%7C01%7Cmark.tovey%40dsv.com%7Ce9260521e8e247ed5a3e08d6d34bdc0b%7C4a90c23a3ece4ef2b857522f23b8204c%7C0%7C0%7C636928720097890069&sdata=ItDy%2BYpkJaXtXrehCfo5T7jxdGEpcXWKhGGtZXmtQ8Y%3D&reserved=0>.
For more options, visit 
https://groups.google.com/d/optout<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Foptout&data=02%7C01%7Cmark.tovey%40dsv.com%7Ce9260521e8e247ed5a3e08d6d34bdc0b%7C4a90c23a3ece4ef2b857522f23b8204c%7C0%7C0%7C636928720097900077&sdata=8fxOojNBy%2BPxKqrPzWcOqX9SSBXy4czQzGI%2FgMJEkys%3D&reserved=0>.

-- 
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/AM5PR0602MB277194548FF93FCDDFC158D79E320%40AM5PR0602MB2771.eurprd06.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to