# Should be simple... Seems like command's chdir parameter doesn't work...

**URL:** <https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541>\
**Category:** Ansible Project\
**Created:** [July 23, 2021, 2:07pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541 "2021-07-23T14:07:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [July 23, 2021, 2:07pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/1 "2021-07-23T14:07:13Z")

</div>

Seems like the module command: parameter isn’t working. Anyone have the same error?

playbook:

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 23, 2021, 2:23pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/2 "2021-07-23T14:23:59Z")

</div>

> Seems like the module command: parameter isn’t working. Anyone have the same error?

Hello Mike,

the tar binary is probably missing in the $PATH Ansible is using. The $PATH is most likely different compared to $PATH  
the interactive shell is using on the host.

Also consider to use the unarchive module instead.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [July 23, 2021, 2:53pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/3 "2021-07-23T14:53:21Z")

</div>

I looked for a “tar” module; I had forgotten about “unarchive”. I have changed my playbook and the relevant changed sections are below. I still get an error:

The changed sections of the playbook:

- name: “copy {{file}} to the {{ansible\_host}}”  
copy:  
src=“…/templates/{{file}}”  
dest=“{{installdir}}/{{file}}”  
owner=“root”  
group=“root”  
mode=“0644”  
backup=“yes”

- name: “extract {{file}}”  
unarchive:  
src=“{{installdir}}/{{file}}”  
dest=“{{installdir}}”  
register: x

- debug:  
msg=“installdir=‘{{installdir}}’ file=‘{{file}}’ command=‘{{y}}’ unarchive='{{x}}”

- fail: msg=“doing fail for testing”

Output from: ansible-playbook —limit had-dbora-s1 -vvv carbonblackresponse.yml

2021-07-23 10:38:59,326 p=3699 u=meggleston n=ansible | TASK [extract CarbonBlackLinuxDevelopment-210721.tar.gz] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
2021-07-23 10:38:59,346 p=3751 u=meggleston n=ansible | ESTABLISH SSH CONNECTION FOR USER: None  
2021-07-23 10:38:59,347 p=3751 u=meggleston n=ansible | SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/meggleston/.ansible/cp/7058214ea1 hqd-dbora-n2 ‘/bin/sh -c ‘"’"’( umask 77 && mkdir -p “`echo /tmp`”&& mkdir “`echo /tmp/ansible-tmp-1627051139.35-3751-266795384375758`” && echo ansible-tmp-1627051139.35-3751-266795384375758=“`echo /tmp/ansible-tmp-1627051139.35-3751-266795384375758`” ) && sleep 0’“'”‘’  
2021-07-23 10:38:59,399 p=3751 u=meggleston n=ansible | (0, ‘ansible-tmp-1627051139.35-3751-266795384375758=/tmp/ansible-tmp-1627051139.35-3751-266795384375758\n’, ‘’)  
2021-07-23 10:38:59,400 p=3751 u=meggleston n=ansible | ESTABLISH SSH CONNECTION FOR USER: None  
2021-07-23 10:38:59,401 p=3751 u=meggleston n=ansible | SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/meggleston/.ansible/cp/7058214ea1 hqd-dbora-n2 ‘/bin/sh -c ‘"’“‘rm -f -r /tmp/ansible-tmp-1627051139.35-3751-266795384375758/ \> /dev/null 2\>&1 && sleep 0’”’"‘’  
2021-07-23 10:38:59,444 p=3751 u=meggleston n=ansible | (0, ‘’, ‘’)  
2021-07-23 10:38:59,449 p=3699 u=meggleston n=ansible | fatal: [hqd-dbora-n2]: FAILED! =\> {  
“changed”: false,  
“msg”: “Could not find or access ‘/tmp/CarbonBlack-install/CarbonBlackLinuxDevelopment-210721.tar.gz’ on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote\_src option”  
}  
2021-07-23 10:38:59,450 p=3699 u=meggleston n=ansible | PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
2021-07-23 10:38:59,451 p=3699 u=meggleston n=ansible | hqd-dbora-n2 : ok=4 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

Output of the directory showing the file is there:

[meggleston@hq-mgtlinux-s1 ~]$ ssh hqd-dbora-n2 ls -l /tmp /tmp/CarbonBlack-install /tmp/CarbonBlack-install/CarbonBlackLinuxDevelopment-210721.tar.gz ; date  
-rw-r–r–. 1 root root 52643490 Jul 23 09:50 /tmp/CarbonBlack-install/CarbonBlackLinuxDevelopment-210721.tar.gz

/tmp:  
total 0  
drwxr-xr-x. 2 root root 55 Jul 23 09:50 CarbonBlack-install

/tmp/CarbonBlack-install:  
total 51412  
-rw-r–r–. 1 root root 52643490 Jul 23 09:50 CarbonBlackLinuxDevelopment-210721.tar.gz  
Fri Jul 23 10:42:39 EDT 2021

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 23, 2021, 3:01pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/4 "2021-07-23T15:01:18Z")

</div>

> I looked for a “tar” module; I had forgotten about “unarchive”. I have changed my playbook and the relevant changed sections are below. I still get an error:

&nbsp;&nbsp;&nbsp;"msg": "Could not find or access '/tmp/CarbonBlack-install/CarbonBlackLinuxDevelopment-210721.tar.gz' on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote\_src option"

What part of this error message is unclear?

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [July 23, 2021, 3:04pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/5 "2021-07-23T15:04:28Z")

</div>

Below the error message I showed where the file does exist on the remote host.

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [July 23, 2021, 3:12pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/6 "2021-07-23T15:12:14Z")

</div>

The file is on the remote host, as shown in the output below the error message, but the error message does say the file for “unarchive” "on the Ansible Controller”. Why is “unarchive” module looking on the Ansible controller for the file?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [July 23, 2021, 3:16pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/7 "2021-07-23T15:16:42Z")

</div>

> The file is on the remote host, as shown in the output below the error message, but the error message does say the file for “unarchive” "on the Ansible Controller”. Why is “unarchive” module looking on the Ansible controller for the file?

It is all in the error message:

expect the file to exist on the remote, see the remote\_src option

Works the same way as "copy" module does.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [July 23, 2021, 3:22pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/8 "2021-07-23T15:22:11Z")

</div>

Duh. Thank you. 🙂

---

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [July 23, 2021, 5:41pm UTC](https://forum.ansible.com/t/should-be-simple-seems-like-commands-chdir-parameter-doesnt-work/35541/9 "2021-07-23T17:41:39Z")

</div>

Well, I changed things around and used the shell module rather than the command module. I put “cd {{installdir}} ; sh {{script}}” in the playbook. The full playbook is here:
