# Executing commands from Lookup Plugin in development

**URL:** <https://forum.ansible.com/t/executing-commands-from-lookup-plugin-in-development/24360>\
**Category:** Ansible Developer\
**Created:** [April 30, 2017, 1:50pm UTC](https://forum.ansible.com/t/executing-commands-from-lookup-plugin-in-development/24360 "2017-04-30T13:50:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jparrill](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jparrill](https://forum.ansible.com/u/jparrill)\
**Post date:** [April 30, 2017, 1:50pm UTC](https://forum.ansible.com/t/executing-commands-from-lookup-plugin-in-development/24360/1 "2017-04-30T13:50:48Z")

</div>

Hi there pals,

I am developing a **Lookup** plugin and I’m trying to figure out which is the best way to execute a system command using the built-ins from Ansible utils.

I am trying to use those libraries to call to a system command that the binary exists on /usr/bin folder:

- from ansible.utils.cmd\_functions import run\_cmd

- the os one with

> - os.system

> - subprocess.call

> - subprocess.Popen

But with all of them I get this error:

`

fatal: [vagrantServer]: FAILED! =\> {  
“failed”: true,  
“msg”: “An unhandled exception occurred while running the lookup plugin ‘hiera’. Error was a \<type ‘exceptions.OSError’\>, original message: [Errno 2] No such file or directory”

`

I have no problems using run\_command library from a module, but this is not a module, it’s a plugin. Any ideas of how to solve it?

Thanks in advance.

Best regards

PS: Yeah, I’m pointing to the correct server and also the binary exists on it ;).  
PS2: If I try to use for example Date commands, it works fine

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [April 30, 2017, 2:20pm UTC](https://forum.ansible.com/t/executing-commands-from-lookup-plugin-in-development/24360/2 "2017-04-30T14:20:17Z")

</div>

Lookup plugins execute on the ansible controller, not on a remote server.

To execute on a remote server it needs to be a module.

---

<div class="post-metadata">

**Author:** ![jparrill](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@jparrill](https://forum.ansible.com/u/jparrill)\
**Post date:** [April 30, 2017, 2:44pm UTC](https://forum.ansible.com/t/executing-commands-from-lookup-plugin-in-development/24360/3 "2017-04-30T14:44:46Z")

</div>

Great, thats the reason of this behaviour :), Thanks Matt I will face the problem in a different way :).

Maybe I skip this part from documentation :).

Have a nice day.
