Chef recipe error

Hi,

Rather dumfounded on why I get an error with this recipe…The file is
there. Why does chef complain that it is not? This should be so
simple…a template changes then source my .bashrc file.

ubuntu@ubuntu:~$ ls /home/ubuntu/.bash_includes
/home/ubuntu/.bash_includes

execute “add_include_to_bashrc” do
user “ubuntu"
command “echo ‘source /home/ubuntu/.bash_includes’ | tee -a
/home/ubuntu/.bashrc"
action :run
ignore_failure true
not_if {File.exists?(”/home/ubuntu/.bash_includes”)}
end

execute “source_bashrc” do
user "ubuntu"
command "source /home/ubuntu/.bashrc"
action :nothing
end

template “/home/ubuntu/.bash_includes” do
path "/home/ubuntu/.bash_includes"
source "bash_includes.erb"
owner "ubuntu"
group "ubuntu"
mode "0770"
notifies :run, “execute[source_bashrc]”, :immediately
end

================================================================================
Error executing action run on resource ‘execute[source_bashrc]’

Errno::ENOENT

No such file or directory - source /home/ubuntu/.bashrc

Resource Declaration:

In /home/ubuntu/workspace/Chef/chef-repo/cookbooks/bash/recipes/local.rb

12: execute “source_bashrc” do
13: user "ubuntu"
14: command "source /home/ubuntu/.bashrc"
15: action :nothing
16: end
17:

Compiled Resource:

Declared in

/home/ubuntu/workspace/Chef/chef-repo/cookbooks/bash/recipes/local.rb:12:in
`from_file’

execute(“source_bashrc”) do
action [:nothing]
retries 0
retry_delay 2
command "source /home/ubuntu/.bashrc"
backup 5
returns 0
user "ubuntu"
cookbook_name :bash
recipe_name "local"
end

Le 2013-09-03 08:39, David Montgomery a écrit :

================================================================================

Error executing action run on resource 'execute[source_bashrc]'

================================================================================

Errno::ENOENT

No such file or directory - source
/home/ubuntu/.bashrc

Resource Declaration:


In

/home/ubuntu/workspace/Chef/chef-repo/cookbooks/bash/recipes/local.rb

12: execute "source_bashrc" do
13: user "ubuntu"
14: command
"source /home/ubuntu/.bashrc"
15: action :nothing
16: end

17:

Quite clear I think, you're trying to execute a command named
source by a system call, source is a bult-in inside bash/tcsh/etc.

Change your resource to be bash.

Seen on docs.opscode.com for the
execute resource:

SOURCING A FILE

The EXECUTE resource cannot be
used to source a file (e.g. command "source filename"). The following
example will fail becausesource is not an executable:

execute "foo"
do
command "source /tmp/foo.sh"
end

Instead, use the SCRIPT resource
or one of the SCRIPT-based resources (BASH, CSH, PERL, PYTHON, or RUBY).
For example:

bash "foo" do
code "source
/tmp/foo.sh"
end

regards,

Tensibai

On Tuesday, September 3, 2013 at 2:13 AM, Tensibai wrote:

Le 2013-09-03 08:39, David Montgomery a écrit :

================================================================================
Error executing action run on resource 'execute[source_bashrc]'

Errno::ENOENT

No such file or directory - source /home/ubuntu/.bashrc

Resource Declaration:

In /home/ubuntu/workspace/Chef/chef-repo/cookbooks/bash/recipes/local.rb

12: execute "source_bashrc" do
13: user "ubuntu"
14: command "source /home/ubuntu/.bashrc"
15: action :nothing
16: end
17:

Quite clear I think, you're trying to execute a command named source by a system call, source is a bult-in inside bash/tcsh/etc.
Change your resource to be bash.
Seen on docs.opscode.com (http://docs.opscode.com) for the execute resource:
Sourcing a file
The execute resource cannot be used to source a file (e.g. command "source filename"). The following example will fail becausesource is not an executable:
execute "foo" do command "source /tmp/foo.sh (http://foo.sh)" end

Instead, use the script resource or one of the script-based resources (bash, csh, perl, python, or ruby). For example:
bash "foo" do code "source /tmp/foo.sh (http://foo.sh)" end

regards,

Tensibai

Additionally, this command isn't going to have the result you're expecting. UNIX processes inherit environment variables from their parent process, but changing environment variables in the child won't affect the parent (if this wasn't the case, changes to things like HOME and PATH would propagate all the way back up to init, and then back down to other users' shells and such).

If you need to set environment variables so that every command chef executes has access to them, then you need to set them via ruby's ENV, for example:

ENV["PATH"] = "/opt/something/bin:" + ENV["PATH"]

If you only need to set the environment for one or two commands, you can do this with the environment attribute of the execute resource: execute Resource

HTH,

Daniel DeLeo