# local\_action. Current working directory

**URL:** <https://forum.ansible.com/t/local-action-current-working-directory/38128>\
**Category:** Ansible Project\
**Created:** [June 19, 2023, 6:12pm UTC](https://forum.ansible.com/t/local-action-current-working-directory/38128 "2023-06-19T18:12:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![user17](https://avatars.discourse-cdn.com/v4/letter/u/a9a28c/32.png) [@user17](https://forum.ansible.com/u/user17)\
**Post date:** [June 19, 2023, 6:12pm UTC](https://forum.ansible.com/t/local-action-current-working-directory/38128/1 "2023-06-19T18:12:56Z")

</div>

I’m executing the same script at two different hosts. Script just returns current working directory:

tasks:

- name: Get exec\_path localaction  
local\_action: command pwd  
register: res
- debug: var=res.stdout\_lines

At both hosts script is locted in /opt/test  
In one host I’m getting script location:  
TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [single] =\> {  
“res.stdout\_lines”: [  
“/opt/test”  
]  
}

On another: /root

TASK [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [single] =\> {  
“res.stdout\_lines”: [  
“/root”  
]  
}

Why it is so? How to make on second host run local\_action from scrit location?

---

<div class="post-metadata">

**Author:** ![dnmvisser](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@dnmvisser](https://forum.ansible.com/u/dnmvisser)\
**Post date:** [June 20, 2023, 4:34pm UTC](https://forum.ansible.com/t/local-action-current-working-directory/38128/2 "2023-06-20T16:34:22Z")

</div>

I have no idea. Can be many things, home directory of the user account you’re using, for one.  
But why do you want to rely on something that is (clearly) not stable?  
I would just set a directory and make sure it’s there, and use that to do what needs to be done.  
It’s also more according to the ansible philosophy, I think, to make things explicit rather than depending on things that may be different (for reasons that you don’t know, in this case).

Dick

---

<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:** [June 20, 2023, 4:41pm UTC](https://forum.ansible.com/t/local-action-current-working-directory/38128/3 "2023-06-20T16:41:33Z")

</div>

The 'script' action would copy a script from the controller to the  
target, run it and remove it, that way you can store it in a  
predictable spot adjacent to playbook or in role.  
Also you only need to ever update 1 copy of it.
