# FYI: What is PWD when executed as  host:localhost vs delegate\_to vs local\_action  ?

**URL:** <https://forum.ansible.com/t/fyi-what-is-pwd-when-executed-as-host-localhost-vs-delegate-to-vs-local-action/15552>\
**Category:** Ansible Project\
**Created:** [June 25, 2014, 10:27pm UTC](https://forum.ansible.com/t/fyi-what-is-pwd-when-executed-as-host-localhost-vs-delegate-to-vs-local-action/15552 "2014-06-25T22:27:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Larry\_Fast](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Larry\_Fast](https://forum.ansible.com/u/Larry_Fast)\
**Post date:** [June 25, 2014, 10:27pm UTC](https://forum.ansible.com/t/fyi-what-is-pwd-when-executed-as-host-localhost-vs-delegate-to-vs-local-action/15552/1 "2014-06-25T22:27:04Z")

</div>

Thought I’d share some gory details I just worked through. I was writing a self-check playbook and wanted to look at files in the playbook directory. Note that a module would probably solve my problem more effectively than PB code but here’s what I found…

1. vars.playbook\_dir=‘.’ - as you’ll see this doesn’t necessarily take you to the right location
2. vars.inventory\_dir= - this is better but only if inventory\_dir=playbook\_dir

So my attempts to use #1 went south until I discovered the following variations. As stated in the documentation, local\_action is an alias for delegate\_to: localhost or 127.0.0.1. What’s not stated is that “delegate\_to localhost” is treated as a special case. delegate\_to any-other-server will work the same as hosts: any-other-server

- hosts: localhost  
ssh\_user: hi\_there  
tasks:

- name: pwd\_localhost  
command: pwd =\> /home/hi\_there  
register: pwd\_localhost

- name: pwd\_delegate\_dns

command: pwd =\> /home/hi\_there  
delegate\_to: dns\_of\_localhost  
register: pwd\_delegate\_dns

- name: pwd\_delegate\_localhost

command: pwd =\>   
delegate\_to: localhost  
register: pwd\_delegate\_localhost

- name: pwd\_local\_action  
local\_action: command pwd =\>   
register: pwd\_local\_action

- name: pwd\_127

command: pwd =\>   
delegate\_to: 127.0.0.1  
register: pwd\_127

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [June 25, 2014, 10:41pm UTC](https://forum.ansible.com/t/fyi-what-is-pwd-when-executed-as-host-localhost-vs-delegate-to-vs-local-action/15552/2 "2014-06-25T22:41:10Z")

</div>

No offense intended, but care to relate what you found in words and what you mean by “a special case” ?

I also don’t know what you mean by “vars.playbook\_dir” with the dot notation, which is difficult because I wrote the program 🙂
