0

Can somebody tell me how to append to PATH variable in Linux? I have already checked a similar question (puppet - How do I append to path variable?) but that answers for all new login shells whereas I am considered about the current session as well.

I have already tried:

exec { 'export-path':
  command => "/bin/bash -c 'export PATH=/path/to/custom/bin:$PATH'",
}
Community
  • 1
  • 1
Ketul Patani
  • 101
  • 1
  • 9
  • 1
    To answer this properly, why do you need to set the path? – Alex Harvey May 01 '17 at 00:19
  • 1
    What exactly do you mean by "the current session" in Puppet context? Are you asking how to instruct the puppet process to change *its own* path? If so, then to what end? Are you looking for a way to propagate additional path directories to `Exec`s Puppet runs? The answers to the question you linked appear to cover the topic very well already; in particular, do not overlook the first part of the accepted answer. If indeed there remains a gap, then please clarify just what it is you want to know. – John Bollinger May 01 '17 at 03:18
  • I agree with Alex that clarification on the "why" is important here and with John that what the asker means by "current session" is unclear and that the linked answer seems to address this well already. – Matthew Schuchard May 01 '17 at 19:16
  • I am currently writing a puppet module to install a custom build of nginx and would like to append the path of the nginx bin to the PATH variable. And 'Current session' means the current terminal session like if I execute export command, the PATH should be immediately updated. – Ketul Patani May 02 '17 at 08:31
  • That is more of a linux question than a Puppet question. – Matthew Schuchard May 02 '17 at 14:55
  • Actually, the command fine when executed manually but doesn't when executed in manifest. – Ketul Patani May 02 '17 at 14:58

1 Answers1

0

The proper way to set PATH in puppet command resource is, use path option directly.

Here is the sample

exec { 'tar -xf /Volumes/nfs02/important.tar':
  cwd     => '/var/tmp',
  creates => '/var/tmp/myfile',
  path    => ['/usr/bin', '/usr/sbin',],
}

Refer:

Resource Type: exec

BMW
  • 42,880
  • 12
  • 99
  • 116
  • 1
    This answer is factually correct, but I suspect it answers a different question than the OP thinks he posed. – John Bollinger May 01 '17 at 03:06
  • Why do you think that's not related? The way poster working on is the wrong direction. You need to drag him back on the right track. – BMW May 01 '17 at 03:41
  • 1
    I didn't say I thought this answer was *unrelated* to the question. That's a different matter. Whether you want to "drag him back on the right track" is your concern, but any answer ought to first and foremost address the question that is actually posed. – John Bollinger May 01 '17 at 13:44