Last active
December 17, 2015 08:59
-
-
Save DazWorrall/5584358 to your computer and use it in GitHub Desktop.
Different value of `inject` in ansible lookup plugins. In the first case, `inject` is a dictionary with host/group/fact data, in the second case, its a function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Place in lookup_plugins/foo/mytest.py | |
from ansible import utils | |
class LookupModule(object): | |
def __init__(self, basedir=None, **kwargs): | |
self.basedir = basedir | |
def run(self, terms, inject=None, **kwargs): | |
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject) | |
ret = [] | |
if not isinstance(terms, list): | |
terms = [ terms ] | |
for term in terms: | |
ret.append(repr(inject)) # This is what we're interested in | |
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ansible-playbook -c local -i localhost, test.yml | |
PLAY [all] ******************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [debug msg={{item}}] **************************************************** | |
ok: [localhost] => (item={'delegate_to': None, u'ansible_en1': ....<snipped, there is a bunch of fact/host/group data here>'}) | |
TASK: [debug msg=<built-in function vars>] ************************************ | |
ok: [localhost] | |
PLAY RECAP ******************************************************************** | |
localhost : ok=3 changed=0 unreachable=0 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
tasks: | |
- debug: msg={{ item }} | |
with_mytest: foo | |
- debug: msg={{ lookup('mytest','foo') }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment