Przemek
2013-Jul-17 07:56 UTC
[Puppet Users] Importing environmental variables from file via exec
Hi Puppet Community, I prepare manifests and modules to deploy stuff that I need on agent. During building postgres database I have to export some environmental UNIX variables stored in "some_file.conf". Standard procedure to do this is simply run command: root@hostname:/path_to_config_file# . some_file.conf>and after this I see all exported variables ("env" command in terminal). Now when I trying do the same thing in puppet exec but variables wont export (no error feedback from agent on debug mode). Puppet code: exec {"enviroments":> command => ''/bin/sh -c ". some_file.conf"'', > path => ["/bin", "/usr/bin","/path_to_config_file"], > cwd => "/path_to_config_file", > refreshonly => false, > require => File["/path_to_config_file/some_file.conf"], > } >Puppet version: 3.1.1 Distributor ID: Debian Description: Debian GNU/Linux 6.0.7 (squeeze) Release: 6.0.7 Codename: squeeze I will be very grateful for any help, clues or tips that lead me to resolve this problem. P.S Sorry for my grammar and poor English. Best Regards -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
jcbollinger
2013-Jul-17 14:25 UTC
[Puppet Users] Re: Importing environmental variables from file via exec
On Wednesday, July 17, 2013 2:56:34 AM UTC-5, Przemek wrote:> > Hi Puppet Community, > > I prepare manifests and modules to deploy stuff that I need on agent. > During building postgres database I have to export some environmental UNIX > variables stored in "some_file.conf". > Standard procedure to do this is simply run command: > > root@hostname:/path_to_config_file# . some_file.conf >> > > and after this I see all exported variables ("env" command in terminal). > > Now when I trying do the same thing in puppet exec but variables wont > export (no error feedback from agent on debug mode). > Puppet code: > > exec {"enviroments": >> command => ''/bin/sh -c ". some_file.conf"'', >> path => ["/bin", "/usr/bin","/path_to_config_file"], >> cwd => "/path_to_config_file", >> refreshonly => false, >> require => File["/path_to_config_file/some_file.conf"], >> } >> > >You seem to have a misconception about the scope of environment variables. Every process has its own, independent environment. When one process spawns another, the child''s environment is initialized with copies of those parent-process environment variables that are marked for export, but once a process has started, no changes to another process''s (even its parent''s or child''s) environment has any effect on its own environment. In your case, when that Exec is applied, it launches /bin/sh (presumably a Bourne-compatible shell such as bash), instructing it to execute the commands it finds in some_file.conf. In particular, environment variable assignments in that file are executed, modifying the environment *of that shell process*. If those environment variables are marked for export, then processes subsequently launched *by that shell* will receive copies of those variables in their environments, too. None of that can have any effect on processes launched outside the scope of that Exec''s shell process, including the puppet agent''s own top-level process or any other process launched by it. Everything runs successfully and correctly; it''s just not a useful thing to do.> Puppet version: 3.1.1 > Distributor ID: Debian > Description: Debian GNU/Linux 6.0.7 (squeeze) > Release: 6.0.7 > Codename: squeeze > > I will be very grateful for any help, clues or tips that lead me to > resolve this problem.If the original idea was to subsequently apply additional Execs that rely on the environment you are trying to initialize, then the solution is to wrap it all up into a single Exec. You can do that by writing a wrapper script around the whole thing, using a File resource to ensure it present on the target node, then Execing that, or if it''s simple enough then you can do that directly via a more clueful Exec. For example, exec { ''pg_setup'': command => ''. some_file.conf && do_step_1 && do_step_2'', path => [''/bin'', ''/usr/bin'', ''/sbin'', ''/usr/sbin'', ''/path/to/setup_scripts'' ], cwd => ''/path/to/config_file'', require => File[''/path/to/config_file/some_file.conf''], provider => ''shell'' } John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Przemek
2013-Jul-18 07:24 UTC
[Puppet Users] Re: Importing environmental variables from file via exec
John, Thank You for excellent explanation! Wrapping it all up into a single Exec works. Moreover now I understand how to puppet execute shell commands. Wrapping is now only way to deploy postgresql database in my environment. Best Regards W dniu środa, 17 lipca 2013 09:56:34 UTC+2 użytkownik Przemek napisał:> > Hi Puppet Community, > > I prepare manifests and modules to deploy stuff that I need on agent. > During building postgres database I have to export some environmental UNIX > variables stored in "some_file.conf". > Standard procedure to do this is simply run command: > > root@hostname:/path_to_config_file# . some_file.conf >> > > and after this I see all exported variables ("env" command in terminal). > > Now when I trying do the same thing in puppet exec but variables wont > export (no error feedback from agent on debug mode). > Puppet code: > > exec {"enviroments": >> command => ''/bin/sh -c ". some_file.conf"'', >> path => ["/bin", "/usr/bin","/path_to_config_file"], >> cwd => "/path_to_config_file", >> refreshonly => false, >> require => File["/path_to_config_file/some_file.conf"], >> } >> > > Puppet version: 3.1.1 > Distributor ID: Debian > Description: Debian GNU/Linux 6.0.7 (squeeze) > Release: 6.0.7 > Codename: squeeze > > I will be very grateful for any help, clues or tips that lead me to > resolve this problem. > P.S > Sorry for my grammar and poor English. > > Best Regards >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.