Unable to source a script?

4,300 views
Skip to first unread message

Dean Mills

unread,
Jun 19, 2015, 1:12:58 PM6/19/15
to ansible...@googlegroups.com
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

Brian Coca

unread,
Jun 19, 2015, 1:13:39 PM6/19/15
to ansible...@googlegroups.com
use shell: module,e, source is a built in which you cannot use unless
you invoke it from a shell.




--
Brian Coca

Dean Mills

unread,
Jun 19, 2015, 1:20:46 PM6/19/15
to ansible...@googlegroups.com
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

Brian Coca

unread,
Jun 19, 2015, 1:32:20 PM6/19/15
to ansible...@googlegroups.com
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
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/0f088d02-6917-4844-96d5-55da0f5a69d1%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Dean Mills

unread,
Jun 19, 2015, 1:37:10 PM6/19/15
to ansible...@googlegroups.com
Awesome, . was what I was after, now onto the next error! :) Thanks Brian!

D

Jitendra Bhalothia

unread,
Dec 12, 2016, 10:11:36 AM12/12/16
to Ansible Project

Hi People,

You have to define the executable path.
 
- name: for source command
  command: source /home/ubuntu/.bash_profile  executable=/bin/bash

guodo...@gmail.com

unread,
May 25, 2017, 11:54:40 AM5/25/17
to Ansible Project
thx ,it worked!

在 2016年12月12日星期一 UTC+8下午11:11:36,Jitendra Bhalothia写道:
Reply all
Reply to author
Forward
0 new messages