# Change current directory

**URL:** <https://forum.ansible.com/t/change-current-directory/30330>\
**Category:** Ansible Project\
**Created:** [May 15, 2019, 12:20am UTC](https://forum.ansible.com/t/change-current-directory/30330 "2019-05-15T00:20:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Kwon](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kevin\_Kwon](https://forum.ansible.com/u/Kevin_Kwon)\
**Post date:** [May 15, 2019, 12:20am UTC](https://forum.ansible.com/t/change-current-directory/30330/1 "2019-05-15T00:20:01Z")

</div>

Hi…

I want to change the current directory in remote host by Ansible.  
so, i have created the playbook like below. but, it is not working correctly.

would you please let me know how can i do change the current directory in the remote host?

Kevin

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [May 15, 2019, 12:24am UTC](https://forum.ansible.com/t/change-current-directory/30330/2 "2019-05-15T00:24:36Z")

</div>

> Hi..
> 
> I want to change the current directory in remote host by Ansible.  
> so, i have created the playbook like below. but, it is not working  
> correctly.

What problem are you actually trying to solve? Maybe try `args: chdir=/mydir`

V/r,  
James Cassell

---

<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:** [May 15, 2019, 2:46pm UTC](https://forum.ansible.com/t/change-current-directory/30330/3 "2019-05-15T14:46:47Z")

</div>

Consider that EACH task get's it's own environment and session, the  
first task hat does a cd, does NOT affect subsequent tasks.

---

<div class="post-metadata">

**Author:** ![Kevin\_Kwon](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Kevin\_Kwon](https://forum.ansible.com/u/Kevin_Kwon)\
**Post date:** [May 17, 2019, 4:42am UTC](https://forum.ansible.com/t/change-current-directory/30330/4 "2019-05-17T04:42:43Z")

</div>

Hi… All  
Thank you so much your help!  
After changed the my playbook like below, working directory is changed.

Kevin

_- name: Go to /cftmp Directory and check the Direcotry in the switch_  
_become: yes_  
_become\_method: sudo_  
_command: ‘pwd’_  
_args:_  
_chdir: /cftmp_  
_register: exec\_result_  
_- debug: var=exec\_result.stdout\_lines_

2019년 5월 15일 수요일 오전 9시 20분 2초 UTC+9, Kevin Kwon 님의 말:
