# Unable to source a script?

**URL:** <https://forum.ansible.com/t/unable-to-source-a-script/18553>\
**Category:** Ansible Project\
**Created:** [June 19, 2015, 5:08pm UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553 "2015-06-19T17:08:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_Mills](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dean\_Mills](https://forum.ansible.com/u/Dean_Mills)\
**Post date:** [June 19, 2015, 5:08pm UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/1 "2015-06-19T17:08:50Z")

</div>

Hi all,

Am trying to install nvm and PM2 from a playbook and I’ve hit a snag. One of the commands I need to run is to source the pm2 users .profile file. The issue is I don’t seem to be able to do that from ansible (am using 1.9.1, in case that matters):

`

- name: Source nvm profile  
command: source /home/pm2/.profile  
sudo: yes  
sudo\_user: pm2

`

Results in:

`  
TASK: [Source nvm profile] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
failed: [10.17.100.59] =\> {“cmd”: “source /home/pm2/.profile”, “failed”: true, “rc”: 2}  
msg: [Errno 2] No such file or directory

FATAL: all hosts have already failed – aborting

`

I’ve confirmed the /home/pm2/.profile file actually exists, anyone have any ideas how I can accomplish this? TIA!

D

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 19, 2015, 5:13pm UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/2 "2015-06-19T17:13:36Z")

</div>

use shell: module,e, source is a built in which you cannot use unless  
you invoke it from a shell.

---

<div class="post-metadata">

**Author:** ![Dean\_Mills](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dean\_Mills](https://forum.ansible.com/u/Dean_Mills)\
**Post date:** [June 19, 2015, 5:20pm UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/3 "2015-06-19T17:20:46Z")

</div>

I get a slightly different error now:

`TASK: [Source nvm profile] **************************************************** `  
`failed: [10.17.100.59] => {"changed": true, "cmd": "source /home/pm2/.profile", "delta": "0:00:00.001528", "end": "2015-06-19 17:18:58.307304", "rc": 127, "start": "2015-06-19 17:18:58.305776", "warnings": []}`  
`stderr: /bin/sh: 1: source: not found`

`FATAL: all hosts have already failed -- aborting`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 19, 2015, 5:32pm UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/4 "2015-06-19T17:32:17Z")

</div>

source is specifically a BASH builtin, you might want to set your  
executable to /bin/bash or make it part of the task, for sh use "."  
to source

---

<div class="post-metadata">

**Author:** ![Dean\_Mills](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dean\_Mills](https://forum.ansible.com/u/Dean_Mills)\
**Post date:** [June 19, 2015, 5:37pm UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/5 "2015-06-19T17:37:10Z")

</div>

Awesome, . was what I was after, now onto the next error! 🙂 Thanks Brian!

D

---

<div class="post-metadata">

**Author:** ![Jitendra\_Bhalothia](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@Jitendra\_Bhalothia](https://forum.ansible.com/u/Jitendra_Bhalothia)\
**Post date:** [December 11, 2016, 7:47am UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/6 "2016-12-11T07:47:11Z")

</div>

Hi People,

You have to define the executable path.

- name: for source command  
command: source /home/ubuntu/.bash\_profile executable=/bin/bash

---

<div class="post-metadata">

**Author:** ![guodongggg](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@guodongggg](https://forum.ansible.com/u/guodongggg)\
**Post date:** [May 24, 2017, 3:24am UTC](https://forum.ansible.com/t/unable-to-source-a-script/18553/7 "2017-05-24T03:24:02Z")

</div>

thx ,it worked!

在 2016年12月12日星期一 UTC+8下午11:11:36，Jitendra Bhalothia写道：
