1

So far, I'm unable to figure out how to duplicate my current dict with k:v addition.

Given this dict example:

list0:
  ct0:
    entry:
      - dest: /tmp
        owner: u1
        source: 

I'd like to get this result (source path being fetched with lookup fileglob):

list0:
  ct0:
    entries:
      - dest: /tmp
        owner: u1
        source: /bar/foo2
      - dest: /tmp
        owner: u1
        source: /bar/foo1
      - dest: /tmp
        owner: u1
        source: /bar/foo0

Did not get anything good yet.

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
Ephe
  • 13
  • 2
  • 3
    `Did not get anything good yet` => this 'anything' is missing in your question. We love implementations, even not good, and throwing errors, because they at least exist and prove you have made an honest attempt to solve the problem by yourself. Moreover they might reveal a bad practice, miss usage, or even an X/Y problem... that will help people giving a better, more accurate answer. Please edit your question and show what you have done so far. As is your question is just seeking for recommendation which is off topic and a very valid close vote reason. – Zeitounator Dec 09 '21 at 18:35

1 Answers1

0

Given the variables

    _dest: /tmp
    _owner: u1
    _source: /bar
    _pattern: foo*

Create the entry in each interaction and concatenate the list, e.g.

    - set_fact:
        entries: "{{ entries|d([]) + [_entry] }}"
      loop: "{{ query('fileglob', _source ~ '/' ~ _pattern) }}"  
      vars:
        _entry: "{{ {'dest': _dest,
                     'owner': _owner,
                     'source': item} }}"

(When you've got the list creating the dictionary is trivial).

Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • Thank you very much @vladimir-botka, works great integrated in my play :) I will update my original post later. – Ephe Dec 16 '21 at 10:40