Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New lookup_plugin for nested dictionary (based on subelements but it will keep the key) #6370

Closed
wants to merge 1 commit into from

Conversation

exarv
Copy link

@exarv exarv commented Mar 10, 2014

New lookup_plugin for nested dictionary (based on subelements but it will keep the key)

The nested list can also be a list in stead of a dictionary, Then the item.1.0 contains 0, 1, 2 and item.1.1 contains the string value

Example:

  • name: test
    action: debug msg="Device {{ item.0.0 }} with details: {{ item.0.1 }} has partition {{ item.1.0 }} with details: {{ item.1.1}}"
    with_nested_dict:
    • ansible_devices
    • partitions

Based on subelements but it will keep the key.

The nested list can also be a list in stead of a dictionary, Then the item.1.0 contains 0, 1, 2 and item.1.1 contains the string value

Example:

- name: test
  action: debug msg="Device {{ item.0.0 }} with details: {{ item.0.1 }} has partition {{ item.1.0 }} with details: {{ item.1.1}}"
  with_nested_dict:
    - ansible_devices
    - partitions
@Peetz0r
Copy link

Peetz0r commented Mar 10, 2014

Awesome! I think I will definately use it someday :)

@mpdehaan
Copy link
Contributor

I'm unlikely to want to expand the iterators for this given this can be solved in a different way, and find the idea of having to say item.1.1 confusing -- with_subelements is confusing enough to explain, and "with_details" is a rather generic name too.

You could solve this by using with_subelements and having a key in the dict that has the value "name".

 mylist:
    - name: bob
      foo: bar
      baz: [ 1,2,3 ]
    - name: alice
      foo: glorp
      baz: [4,5,6]

with_subelements: mylist

That being said there is nothing wrong with you having a customer iterator of your own, we're just not going to want to include it in core.

@mpdehaan mpdehaan closed this Mar 10, 2014
@exarv
Copy link
Author

exarv commented Mar 10, 2014

Ok, you are right. There is a workaround,

But what about the case where you want to iterate over the ansible_devices / partitions? the "sda" and "sda1" values are only available in the keys of the dictionary and not as a separate "name" hashkey.

So this means that the ansible devices / partitions can not be properly used in a task with the standard looping mechanisms of ansible.

I'm happy to change the code to something thats easier to use and not using item.0, item.1 etc.

Or maybe you can have a look at #4982 again.
because that also gives the posibility to use the keys in action, something not available with with_subelements.

Thnx!
Regards,
Robert

@ansible ansible locked and limited conversation to collaborators Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants