# Shell module commands runs on Local Controller

**URL:** <https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346>\
**Category:** Ansible Project\
**Created:** [August 17, 2023, 1:57pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346 "2023-08-17T13:57:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harry\_Clendening](https://avatars.discourse-cdn.com/v4/letter/h/b38774/32.png) [@Harry\_Clendening](https://forum.ansible.com/u/Harry_Clendening)\
**Post date:** [August 17, 2023, 1:57pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/1 "2023-08-17T13:57:39Z")

</div>

Good morning,

I am attempting to use the (shell:) command to obtain the disk space for a remote host. Once I get the command working, I’ll then use AWK to filter the output.

However, the below example playbook insists on running the (shell:) command on the local Ansible control machine, and not the remote host (server1). Thus, I end up with disk space (/var) for the Ansible machine, and NOT the remote host (server1). Does anyone know how what I may be doing wrong? Other commands for example (bigip\_command:) run on the remote host fine.

If I enter a directory (chdir:) that only exists on the remote host, Ansible throws an error like “Directory does not exist”, which is true, as it is looking on the local machine.

Thank you!

- name: Test Playbook  
hosts: server1  
connection: local  
gather\_facts: true

- name: Display Disk Space

shell:

cmd: df /var  
chdir: /var  
register: disk\_space\_output

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 17, 2023, 1:59pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/2 "2023-08-17T13:59:50Z")

</div>

That is becase 'connection: local' forces using the 'local' connection  
plugin, which means that instead of executing on the target it 'forks  
locally' to execute the module.  
Just remove it, 99% of the time you do not need to specify `connection`.

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [August 17, 2023, 2:24pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/3 "2023-08-17T14:24:39Z")

</div>

> Just remove it, 99% of the time you do not need to specify `connection`.

… and you still can delegate individual tasks to localhost when needed …

Walter

---

<div class="post-metadata">

**Author:** ![Harry\_Clendening](https://avatars.discourse-cdn.com/v4/letter/h/b38774/32.png) [@Harry\_Clendening](https://forum.ansible.com/u/Harry_Clendening)\
**Post date:** [August 17, 2023, 2:26pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/4 "2023-08-17T14:26:35Z")

</div>

Hello Brian. Thank you for your reply. Please all me to provide some additional context based on your suggestion (I should have mentioned this on my initial post):

We are working with F5 BIG-IP devices and using REST API (443) ([https://clouddocs.f5.com/products/orchestration/ansible/devel/usage/playbook\_tutorial.html](https://clouddocs.f5.com/products/orchestration/ansible/devel/usage/playbook_tutorial.html)) for the remote device connection, and not SSH (22). If I remove (connection: local), Ansible try’s to connect using SSH (22) (which is blocked). Since the (shell:) module does not appear to support the F5 (provider:) credentials/connection (please see example below), I’m not sure how to get (shell:) to connect to a remote host. I have tried adding (delegate\_to: server1) to the (shell:) command and it simply ignores it.

vars:  
provider:  
password: password  
server: 1.1.1.1  
user: admin\_name  
validate\_certs: no  
server\_port: 443

---

<div class="post-metadata">

**Author:** ![Harry\_Clendening](https://avatars.discourse-cdn.com/v4/letter/h/b38774/32.png) [@Harry\_Clendening](https://forum.ansible.com/u/Harry_Clendening)\
**Post date:** [August 17, 2023, 2:32pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/5 "2023-08-17T14:32:43Z")

</div>

I can get the basic disk space command (df) to work when using a F5 module (bigip\_command:) (which does use provider:). However, the F5 modules do not support (AWK, GREP, SED, etc.) (which is a bummer), like (shell:) and (command:) do. I may end up having to use (bigip\_command:) to grab the disk space, and then use a separate Ansible (regex\_search) task to filter for what I want, which is what I have done in the past (albeit this is an extra step).

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [August 17, 2023, 2:40pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/6 "2023-08-17T14:40:41Z")

</div>

If the F5 is returning structured data (ie. JSON), then set\_fact tasks with filters can help you get to what you need.

Walter

---

<div class="post-metadata">

**Author:** ![Harry\_Clendening](https://avatars.discourse-cdn.com/v4/letter/h/b38774/32.png) [@Harry\_Clendening](https://forum.ansible.com/u/Harry_Clendening)\
**Post date:** [August 17, 2023, 11:11pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/7 "2023-08-17T23:11:24Z")

</div>

Agreed. This is essentially what I am doing now and it does work (pipe var to regex\_search, etc.). I was just hoping to get the (shell:) command to work in our environment, but with our setup, it does not appear to be possible. I should also be to take the (bigip\_command:) output, write the JSON to file, and then run AWK against the file. I have not tried this yet. I’ll probably just stick with (regex\_search) for now. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [August 21, 2023, 2:40pm UTC](https://forum.ansible.com/t/shell-module-commands-runs-on-local-controller/38346/8 "2023-08-21T14:40:38Z")

</div>

shell and command require python on the remote, try raw instead
