Debian Codegraph @

lib/ansible/plugins/lookup/items.py

raw
1 # (c) 2012, Michael DeHaan <[email protected]>
2 # (c) 2017 Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4 from __future__ import annotations
5
6 DOCUMENTATION = """
7 name: items
8 author: Michael DeHaan
9 version_added: historical
10 short_description: list of items
11 description:
12 - this lookup returns a list of items given to it, if any of the top level items is also a list it will flatten it, but it will not recurse
13 notes:
14 - this is the standard lookup used for loops in most examples
15 - check out the 'flattened' lookup for recursive flattening
16 - if you do not want flattening nor any other transformation look at the 'list' lookup.
17 positional: _terms
18 options:
19 _terms:
20 description: list of items
21 required: True
22 """
23
24 EXAMPLES = """
25 - name: "loop through list"
26 ansible.builtin.debug:
27 msg: "An item: {{ item }}"
28 with_items:
29 - 1
30 - 2
31 - 3
32
33 - name: add several users
34 ansible.builtin.user:
35 name: "{{ item }}"
36 groups: "wheel"
37 state: present
38 with_items:
39 - testuser1
40 - testuser2
41
42 - name: "loop through list from a variable"
43 ansible.builtin.debug:
44 msg: "An item: {{ item }}"
45 with_items: "{{ somelist }}"
46
47 - name: more complex items to add several users
48 ansible.builtin.user:
49 name: "{{ item.name }}"
50 uid: "{{ item.uid }}"
51 groups: "{{ item.groups }}"
52 state: present
53 with_items:
54 - { name: testuser1, uid: 1002, groups: "wheel, staff" }
55 - { name: testuser2, uid: 1003, groups: staff }
56
57 """
58
59 RETURN = """
60 _raw:
61 description:
62 - once flattened list
63 type: list
64 """
65
66 from ansible.plugins.lookup import LookupBase
67
68
69 class LookupModule(LookupBase):
70
71 def run(self, terms, variables=None, **kwargs):
72
73 return self._flatten(terms)