# Trying to run script from inside directory

**URL:** <https://forum.ansible.com/t/trying-to-run-script-from-inside-directory/18187>\
**Category:** Ansible Project\
**Created:** [May 7, 2015, 9:04pm UTC](https://forum.ansible.com/t/trying-to-run-script-from-inside-directory/18187 "2015-05-07T21:04:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [May 7, 2015, 9:04pm UTC](https://forum.ansible.com/t/trying-to-run-script-from-inside-directory/18187/1 "2015-05-07T21:04:51Z")

</div>

I’m using ‘unarchive’ to extract a tarball to /tmp/ Inside, I have a shell script with includes references to relative paths. This made my script fail as it was looking for the files relative to whatever directory it’s running from. Looking at ‘shell’ and ‘command’ I see a chdir argument, but I cannot get it to work. If I:

command: insert\_certs.sh chdir=/tmp/dod\_java\_certs/

I get:

TASK: [Run DoD certificate installer] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [vdara] =\> {“cmd”: “insert\_certs.sh”, “failed”: true, “rc”: 2}  
msg: [Errno 2] No such file or directory

If I:

command: insert\_certs.sh  
args:  
chdir=/tmp/dod\_java\_certs/

I get:

TASK: [Run DoD certificate installer] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [vdara] =\> args must be a dictionary, received chdir=/tmp/dod\_java\_certs/

I get the same problems when using ‘shell’. I was, though, able to:

shell: “cd /tmp/dod\_java\_certs; ./insert\_certs.sh”

So how would one correctly use the chdir argument?

---

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [May 8, 2015, 9:31am UTC](https://forum.ansible.com/t/trying-to-run-script-from-inside-directory/18187/2 "2015-05-08T09:31:04Z")

</div>

> I’m using ‘unarchive’ to extract a tarball to /tmp/ Inside, I have a shell script with includes references to relative paths. This made my script fail as it was looking for the files relative to whatever directory it’s running from. Looking at ‘shell’ and ‘command’ I see a chdir argument, but I cannot get it to work. If I:
> 
> command: insert\_certs.sh chdir=/tmp/dod\_java\_certs/
> 
> I get:
> 
> TASK: [Run DoD certificate installer] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> failed: [vdara] =\> {“cmd”: “insert\_certs.sh”, “failed”: true, “rc”: 2}  
> msg: [Errno 2] No such file or directory

This looks fine at a first glance. Check if script has (1) executable permissions; (2) proper shebang at script’s first line.  
(I assume you are sure you do have the script stored on remote host’s /tmp/dod\_java\_certs/insert\_certs.sh at time of executing this … do you?)

> If I:
> 
> command: insert\_certs.sh  
> args:  
> chdir=/tmp/dod\_java\_certs/
> 
> I get:
> 
> TASK: [Run DoD certificate installer] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> fatal: [vdara] =\> args must be a dictionary, received chdir=/tmp/dod\_java\_certs/

Here the reason is you violate the yaml format;  
the correct args definition would be (note the semicolon after chdir):

command: insert\_certs.sh  
args:  
chdir: /tmp/dod\_java\_certs/

(see [http://docs.ansible.com/command\_module.html](http://docs.ansible.com/command_module.html) “Examples”)

HTH,  
-Yassen

---

<div class="post-metadata">

**Author:** ![Yassen\_Damyanov](https://avatars.discourse-cdn.com/v4/letter/y/9fc29f/32.png) [@Yassen\_Damyanov](https://forum.ansible.com/u/Yassen_Damyanov)\
**Post date:** [May 8, 2015, 10:17am UTC](https://forum.ansible.com/t/trying-to-run-script-from-inside-directory/18187/3 "2015-05-08T10:17:15Z")

</div>

You probably need:  
command: ./insert\_certs.sh chdir=/tmp/dod\_java\_certs/

otherwise it looks for **insert\_certs.sh** in PATH, not cwd.
