# Buggy code
def run(self, terms, inject=None, **kwargs):
    terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)

    if isinstance(terms, basestring):
        terms = [terms]

    ret = []
    for term in terms:
        p = subprocess.Popen(
            term,
            cwd=self.basedir,
            shell=False,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
        )
        (stdout, stderr) = p.communicate()
        if p.returncode == 0:
            ret.append(stdout.decode("utf-8").rstrip())
        else:
            raise errors.AnsibleError(
                "lookup_plugin.pipe(%s) returned %d" % (term, p.returncode)
            )
    return ret


# Traceback (OSError)
Traceback (most recent call last):
File "/opt/ansible/bin/ansible-playbook", line 307, in <module>
sys.exit(main(sys.argv[1:]))
File "/opt/ansible/bin/ansible-playbook", line 247, in main
pb.run()
File "/opt/ansible/lib/ansible/playbook/**init**.py", line 247, in run
play = Play(self, play_ds, play_basedir, vault_password=self.vault_password)
File "/opt/ansible/lib/ansible/playbook/play.py", line 99, in **init**
ds = template(basedir, ds, self.vars)
File "/opt/ansible/lib/ansible/utils/template.py", line 349, in template
d[k] = template(basedir, v, vars, lookup_fatal, depth, expand_lists, fail_on_undefined=fail_on_undefined)
File "/opt/ansible/lib/ansible/utils/template.py", line 349, in template
d[k] = template(basedir, v, vars, lookup_fatal, depth, expand_lists, fail_on_undefined=fail_on_undefined)
File "/opt/ansible/lib/ansible/utils/template.py", line 321, in template
varname = template_from_string(basedir, varname, vars, fail_on_undefined)
File "/opt/ansible/lib/ansible/utils/template.py", line 562, in template_from_string
res = jinja2.utils.concat(rf)
File "<template>", line 8, in root
File "/usr/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg/jinja2/runtime.py", line 180, in call
return **obj(_args, *_kwargs)
File "/opt/ansible/lib/ansible/utils/template.py", line 554, in my_lookup
return lookup(_args, basedir=basedir, *_kwargs)
File "/opt/ansible/lib/ansible/utils/template.py", line 91, in lookup
ran = instance.run(_args, inject=vars, *_kwargs)
File "/opt/ansible/lib/ansible/runner/lookup_plugins/pipe.py", line 35, in run
p = subprocess.Popen(term, cwd=self.basedir, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init**
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

# Fixed code
def run(self, terms, inject=None, **kwargs):
    terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)

    if isinstance(terms, basestring):
        terms = [terms]

    ret = []
    for term in terms:
        """
            http://docs.python.org/2/library/subprocess.html#popen-constructor

            The shell argument (which defaults to False) specifies whether to use the 
            shell as the program to execute. If shell is True, it is recommended to pass 
            args as a string rather than as a sequence

            https://github.com/ansible/ansible/issues/6550
            """
        term = str(term)

        p = subprocess.Popen(
            term,
            cwd=self.basedir,
            shell=True,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
        )
        (stdout, stderr) = p.communicate()
        if p.returncode == 0:
            ret.append(stdout.decode("utf-8").rstrip())
        else:
            raise errors.AnsibleError(
                "lookup_plugin.pipe(%s) returned %d" % (term, p.returncode)
            )
    return ret