Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?

2018-10-20 Thread Dmitriy Panteleyev
That is what I ended up doing, but was curious if there is a 'filter' way.


On Saturday, October 20, 2018 at 11:01:32 AM UTC-6, Kai Stian Olstad wrote:
>
> On Saturday, 20 October 2018 17:59:07 CEST Dmitriy Panteleyev wrote: 
> > Is there a way to modify this so that the item to the right of the equal 
> > sign was quoted? 
> > 
> > So...  one="wan", two="too", three="tree" 
>
> You can always use Jinja template 
>
>   - debug: msg="{% for k, v in test.iteritems() %}{{ k }}="{{ v }}"{% if 
> not loop.last %}, {% endif %}{% endfor %}" 
>
> -- 
> Kai Stian Olstad 
>
>
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/eb879aeb-ef35-4bad-8165-98aebae764de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?

2018-10-20 Thread Kai Stian Olstad
On Saturday, 20 October 2018 17:59:07 CEST Dmitriy Panteleyev wrote:
> Is there a way to modify this so that the item to the right of the equal 
> sign was quoted?
> 
> So...  one="wan", two="too", three="tree"

You can always use Jinja template

  - debug: msg="{% for k, v in test.iteritems() %}{{ k }}="{{ v }}"{% if not 
loop.last %}, {% endif %}{% endfor %}"

-- 
Kai Stian Olstad


-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2579372.oObVpghzk8%40x1.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?

2018-10-20 Thread Dmitriy Panteleyev
Is there a way to modify this so that the item to the right of the equal 
sign was quoted?

So...  one="wan", two="too", three="tree"



On Friday, October 19, 2018 at 2:06:01 PM UTC-6, Dmitriy Panteleyev wrote:
>
> I'll give that a try, thank you.
>
>
> On Friday, October 19, 2018 at 12:04:27 PM UTC-6, Matt Martz wrote:
>>
>> This should do the trick:
>>
>> {{ test|dictsort|map('join', '=')|join(', ') }}
>>
>> In my test, it produces:
>>
>> ok: [localhost] => {
>> "msg": "one=wan, three=tree, two=too"
>> }
>>
>> It's ordered slightly different than your version, and dictsort could 
>> help change the sort order, however just a note that python dictionaries in 
>> most python versions are unsorted.
>>
>> On Fri, Oct 19, 2018 at 12:55 PM Dmitriy Panteleyev  
>> wrote:
>>
>>> Given an *arbitrary* dictionary like:
>>>
>>> test:
>>>   one: wan
>>>   two: too
>>>   three: tree
>>>
>>> How can I convert it to a list like:
>>>
>>> test:
>>>   - one=wan
>>>   - two=too
>>>   - thee=tree
>>>
>>> The end result that I need is actually a string of these list items 
>>> ("one=one, two=too, three=tree").  I know that I can easily `join()` a list 
>>> of items, but if there is an easier way to directly convert the dictionary 
>>> to a string, that would work too.
>>>
>>> Again, I know neither the number of dictionary elements, nor the key 
>>> names.
>>>
>>> A solution that works in version 2.5 would be best...
>>>
>>> -- 
>>> 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-proje...@googlegroups.com.
>>> To post to this group, send email to ansible...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/ansible-project/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> -- 
>> Matt Martz
>> @sivel
>> sivel.net
>>
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b8d4b422-9f09-40e5-9802-da587912f62c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?

2018-10-19 Thread Dmitriy Panteleyev
I'll give that a try, thank you.


On Friday, October 19, 2018 at 12:04:27 PM UTC-6, Matt Martz wrote:
>
> This should do the trick:
>
> {{ test|dictsort|map('join', '=')|join(', ') }}
>
> In my test, it produces:
>
> ok: [localhost] => {
> "msg": "one=wan, three=tree, two=too"
> }
>
> It's ordered slightly different than your version, and dictsort could help 
> change the sort order, however just a note that python dictionaries in most 
> python versions are unsorted.
>
> On Fri, Oct 19, 2018 at 12:55 PM Dmitriy Panteleyev  > wrote:
>
>> Given an *arbitrary* dictionary like:
>>
>> test:
>>   one: wan
>>   two: too
>>   three: tree
>>
>> How can I convert it to a list like:
>>
>> test:
>>   - one=wan
>>   - two=too
>>   - thee=tree
>>
>> The end result that I need is actually a string of these list items 
>> ("one=one, two=too, three=tree").  I know that I can easily `join()` a list 
>> of items, but if there is an easier way to directly convert the dictionary 
>> to a string, that would work too.
>>
>> Again, I know neither the number of dictionary elements, nor the key 
>> names.
>>
>> A solution that works in version 2.5 would be best...
>>
>> -- 
>> 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-proje...@googlegroups.com .
>> To post to this group, send email to ansible...@googlegroups.com 
>> .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ee8fdf48-cec1-4af1-b66b-2b8ee9fc27c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?

2018-10-19 Thread Matt Martz
This should do the trick:

{{ test|dictsort|map('join', '=')|join(', ') }}

In my test, it produces:

ok: [localhost] => {
"msg": "one=wan, three=tree, two=too"
}

It's ordered slightly different than your version, and dictsort could help
change the sort order, however just a note that python dictionaries in most
python versions are unsorted.

On Fri, Oct 19, 2018 at 12:55 PM Dmitriy Panteleyev 
wrote:

> Given an *arbitrary* dictionary like:
>
> test:
>   one: wan
>   two: too
>   three: tree
>
> How can I convert it to a list like:
>
> test:
>   - one=wan
>   - two=too
>   - thee=tree
>
> The end result that I need is actually a string of these list items
> ("one=one, two=too, three=tree").  I know that I can easily `join()` a list
> of items, but if there is an easier way to directly convert the dictionary
> to a string, that would work too.
>
> Again, I know neither the number of dictionary elements, nor the key names.
>
> A solution that works in version 2.5 would be best...
>
> --
> 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 post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Matt Martz
@sivel
sivel.net

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD8N0v9HkSFNLQK3exQGdAkKZS9oEuUAV6VbQ6GhWNsp-R0PSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] How to convert a dictionary to a list with key=value elements or to a string with key=value elements?

2018-10-19 Thread Dmitriy Panteleyev
Given an *arbitrary* dictionary like:

test:
  one: wan
  two: too
  three: tree

How can I convert it to a list like:

test:
  - one=wan
  - two=too
  - thee=tree

The end result that I need is actually a string of these list items 
("one=one, two=too, three=tree").  I know that I can easily `join()` a list 
of items, but if there is an easier way to directly convert the dictionary 
to a string, that would work too.

Again, I know neither the number of dictionary elements, nor the key names.

A solution that works in version 2.5 would be best...

-- 
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 post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ad406797-d8bb-4735-bce4-41c9b71a2388%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.