2014-11-05 14:00:00 +00:00
|
|
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
2017-09-19 14:49:07 +00:00
|
|
|
# (c) 2017 Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2015-04-13 20:28:01 +00:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2014-11-05 14:00:00 +00:00
|
|
|
|
2017-09-19 14:49:07 +00:00
|
|
|
DOCUMENTATION = """
|
|
|
|
lookup: items
|
|
|
|
author: Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
version_added: historical
|
|
|
|
short_description: list of items
|
|
|
|
description:
|
2018-04-04 13:52:55 +00:00
|
|
|
- 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
|
2017-09-19 14:49:07 +00:00
|
|
|
notes:
|
|
|
|
- this is the standard lookup used for loops in most examples
|
|
|
|
- check out the 'flattened' lookup for recursive flattening
|
2018-06-13 06:22:42 +00:00
|
|
|
- if you do not want flattening nor any other transformation look at the 'list' lookup.
|
2017-09-19 14:49:07 +00:00
|
|
|
options:
|
|
|
|
_terms:
|
|
|
|
description: list of items
|
|
|
|
required: True
|
|
|
|
"""
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: "loop through list"
|
2018-01-08 22:13:10 +00:00
|
|
|
debug:
|
|
|
|
msg: "An item: {{item}}"
|
2017-09-19 14:49:07 +00:00
|
|
|
with_items:
|
|
|
|
- 1
|
|
|
|
- 2
|
|
|
|
- 3
|
|
|
|
|
|
|
|
- name: add several users
|
|
|
|
user:
|
|
|
|
name: "{{ item }}"
|
|
|
|
groups: "wheel"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- testuser1
|
|
|
|
- testuser2
|
|
|
|
|
|
|
|
- name: "loop through list from a variable"
|
2018-05-23 12:49:30 +00:00
|
|
|
debug:
|
|
|
|
msg: "An item: {{item}}"
|
2017-09-19 14:49:07 +00:00
|
|
|
with_items: "{{ somelist }}"
|
|
|
|
|
|
|
|
- name: more complex items to add several users
|
|
|
|
user:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
uid: "{{ item.uid }}"
|
|
|
|
groups: "{{ item.groups }}"
|
|
|
|
state: present
|
|
|
|
with_items:
|
|
|
|
- { name: testuser1, uid: 1002, groups: "wheel, staff" }
|
|
|
|
- { name: testuser2, uid: 1003, groups: staff }
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
_raw:
|
|
|
|
description:
|
|
|
|
- once flattened list
|
|
|
|
type: list
|
|
|
|
"""
|
|
|
|
|
2015-01-08 16:51:54 +00:00
|
|
|
from ansible.plugins.lookup import LookupBase
|
2014-11-05 14:00:00 +00:00
|
|
|
|
2017-06-02 11:14:11 +00:00
|
|
|
|
2015-01-08 16:51:54 +00:00
|
|
|
class LookupModule(LookupBase):
|
2014-11-05 14:00:00 +00:00
|
|
|
|
2015-01-08 16:51:54 +00:00
|
|
|
def run(self, terms, **kwargs):
|
2015-01-15 07:13:45 +00:00
|
|
|
|
2015-01-08 16:51:54 +00:00
|
|
|
return self._flatten(terms)
|