r/Puppet • • Mar 30 '14

Puppet Bash Provider with Login Shell (fixing $PATH, ... for exec)

http://dracoblue.net/dev/puppet-bash-provider-with-login-shell/
2 Upvotes

14 comments sorted by

4

u/Septotank Mar 30 '14

I would be REALLY wary of creating a Puppet type with a hyphen in it, simply due to Ruby's known issues with hyphens in Class names. You might want to reconsider and use an underscore.

1

u/DracoBlue23 Mar 30 '14 edited Mar 30 '14

Thanks for this hint! I changed it to bash_exec.

6

u/[deleted] Mar 30 '14

Just throw something like this in your site.pp...

Exec { path => "/usr/bin:/usr/sbin/:/bin:/sbin" }

1

u/DracoBlue23 Mar 30 '14

I would do this, but I need a specific rvm path in this case it's:

declare -x PATH="/home/dracoblue/.rvm/gems/ruby-2.0.0-p247/bin:/home/dracoblue/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/dracoblue/.rvm/rubies/ruby-2.0.0-p247/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/vagrant_ruby/bin:/home/dracoblue/.rvm/bin"

and additionally I need every exec to source /home/dracoblue/.rvm/bin/rvm before.

Otherwise I cannot run "rvm current", because it says rvm is not a function.

A simple bash --login (what this helper type does), does fix this issue!

Or do you have any better solution for sourcing those files properly, too?

1

u/burning1rr Mar 31 '14

If you just need a specific path and or environment variables, set them explicitly using execs various parameters. You can interpolate the system $::path fact if needed.

If the required environment is more complex than that, you can always bundle a custom fact with your module that determines the correct defaults.

Both approaches are somewhat simpler and more reliable than invoking a login shell.

5

u/neoice Mar 30 '14

or specify path in every exec{}. and/or use full PATHs. explicit is better than implicit!

2

u/LibidinousIntent Mar 30 '14

Someone had downvoted you, and I'd love to know why. This seems a lot more straightforward than creating a while other exec type.

Maybe they don't realize what you're describing is setting a default?

1

u/burning1rr Mar 31 '14

I'd be very wary of writing a module that relies on site-wide default parameters; this creates undocumented dependencies, potential conflicts, and can complicate testing.

It's sometimes okay when you want to set certain parameters, such as configuring a site-wide filebucket... But I'd generally avoid setting defaults that actually affect the operation of a resource.

1

u/todayismyday2 Mar 30 '14

Are you going to fix puppet-rvm? :)

1

u/DracoBlue23 Mar 30 '14

hmm, what do you mean?

1

u/todayismyday2 Mar 30 '14

For me, it does not source rvm profile and keeps giving the warning about bash login.

1

u/DracoBlue23 Mar 31 '14

1

u/todayismyday2 Mar 31 '14

One of those... Not sure if this one has the same issue.

2

u/burning1rr Mar 31 '14

Why not just use the path fact?

exec { 'rvm current':
  path => $::path,
}

As a side note, it's generally considered bad form to trust user environment variables in automation. For example, you'll notice that both sudo and service sanitize the environment as part of their initialization.