Combine values from multiple lists

62 views
Skip to first unread message

Ryan

unread,
Feb 26, 2019, 6:09:33 PM2/26/19
to Ansible Project

How would I go about printing the values from three lists, so that each line contains elements from each list?  For instance, I can print the values from the lists using:


msg:

   - "Memory: {{ memoryLocator.stdout_lines }}"

   - "Memory: {{ memoryPN.stdout_lines }}"

   - "Memory: {{ memorySN.stdout_lines }}"


This would print the values like:


DIMM1

DIMM2

DIMM3


G55555-111

G55555-111

G55555-111


999000123

999000440

999000554


However, what I would like to do is print the lists so each line of the output would combine


DIMM1 G55555-111 999000123

DIMM1 G55555-111 999000440

DIMM1 G55555-111 999000554



Ryan

unread,
Feb 26, 2019, 6:12:03 PM2/26/19
to Ansible Project
Sorry, the output should be:

DIMM1 G55555-111 999000123

DIMM2 G55555-111 999000440

DIMM3 G55555-111 999000554

Kai Stian Olstad

unread,
Feb 27, 2019, 10:46:54 AM2/27/19
to ansible...@googlegroups.com
On 27.02.2019 00:09, Ryan wrote:
>
>
> How would I go about printing the values from three lists, so that each
> line contains elements from each list? For instance, I can print the
> values from the lists using:

Check out with_together
https://docs.ansible.com/ansible/2.4/playbooks_loops.html#looping-over-parallel-sets-of-data

--
Kai Stian Olstad

Ryan

unread,
Feb 27, 2019, 7:27:33 PM2/27/19
to Ansible Project
Thanks, that worked well.  I am writing this information to a file using lineinfile.  How would I strip off the brackets, quotes and commas?
['DIMM1', 'G55555-111', '999000123']

Kai Stian Olstad

unread,
Feb 28, 2019, 2:10:23 PM2/28/19
to ansible...@googlegroups.com
On 28.02.2019 01:27, Ryan wrote:
> Thanks, that worked well. I am writing this information to a file using
> lineinfile. How would I strip off the brackets, quotes and commas?
> ['DIMM1', 'G55555-111', '999000123']

I'm not sure what you do, but with_together don't produce a list, that must be something you do so just don't do that.


--
Kai Stian Olstad

Ryan

unread,
Feb 28, 2019, 3:02:43 PM2/28/19
to Ansible Project
Sorry, the output is from stdout_lines.  here is the section.

- lineinfile:
    line: "{{ item }}"
    path: "{{ log }}"

   with_together:

     - "{{ memoryLocator.stdout_lines }}"

     - "{{ memoryPN.stdout_lines }}"

     - "{{ memorySN.stdout_lines }}"




The output to the log:
['DIMM1', 'G55555-111', '999000123'] 
['DIMM2', 'G55555-111', '999000440'] 
['DIMM3', 'G55555-111', '999000554'] 

I would like to just have:
DIMM1 G55555-111 999000123
DIMM2 G55555-111 999000440
DIMM3 G55555-111 999000554


Kai Stian Olstad

unread,
Feb 28, 2019, 3:11:30 PM2/28/19
to ansible...@googlegroups.com
On 28.02.2019 21:02, Ryan wrote:
> Sorry, the output is from stdout_lines. here is the section.
>
> - lineinfile:
> line: "{{ item }}"
> path: "{{ log }}"
>
> with_together:
>
> - "{{ memoryLocator.stdout_lines }}"
>
> - "{{ memoryPN.stdout_lines }}"
>
> - "{{ memorySN.stdout_lines }}"
>

Change line to
line: "{{ item.0 }} {{ item.1 }} {{ item.2 }}"


--
Kai Stian Olstad

Ryan

unread,
Mar 4, 2019, 9:15:14 PM3/4/19
to Ansible Project
This worked thanks
Reply all
Reply to author
Forward
0 new messages