Thank you very much for your prompt reply...
Will this work??
class environment {
exec{'oe_run':
path=>'/usr/bin',
command => 'echo PATH=\$PATH:/opt/logstash/bin >>
/etc/profile',
unless => "grep -qFx 'PATH=\$PATH:/opt/logstash/bin'
/etc/profile",
}
On Wednesday, 29 June 2016 12:38:35 UTC-4, Peter Kristolaitis wrote:
>
> First of all, I will say that this is probably a sledgehammer approach to
> accomplishing your goal. Many modern platforms have, in their default
> /etc/profile, support for /etc/profile.d/ that works like a run-parts for
> building the environment. The Puppet Agent package installs its own $PATH
> entry in this way on both CentOS and Ubuntu. So you're probably better
> off managing a file in that location so that it gets auto-included by
> /etc/profile.
>
> Secondly, your problem is variable interpolation. Because you're using
> double quotes around the command and onlyif statments, Puppet is
> interpolating $PATH to be (probably) an empty string, rather than a literal
> "$PATH". You need to either change to single quotes (and then adjust the
> quoting around your grep match string) or escape the $ with \$.
>
> Finally, if you were to use the above solution, it's still a bit of a
> sledgehammer because you're not really modeling state. The best solution
> would actually be to use something like Augeas to examine the file and
> modify as necessary. "exec / onlyif" and "exec / unless" are kind of
> measures-of-last-resort in the Puppet world (now, having said that, I must
> admit that I'm completely guilty of using it myself on occasion :p ).
>
>
> On 2016-06-29 12:19 PM, Andrew Morgan wrote:
>
> I want to check if pattern exist in a file and then if it doesn;t echo
> the pattern in the file.
>
> class environment {
>
> exec{'one_run':
> path=>'/usr/bin',
> command => "echo 'PATH=$PATH:/opt/logstash/bin' >>
> /etc/profile",
> onlyif => "grep -qFx 'PATH=$PATH:/opt/logstash/bin'
> /etc/profile",
> }
> }
>
> The above doesn't work,can anyone help with this please? I want to check
> if PATH=$PATH:/opt/logstash/bin' exists in /etc/profile and if not input it
> only once.
> --
> 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 [email protected] <javascript:>.
> To view this discussion on the web visit
> <https://groups.google.com/d/msgid/puppet-users/1b36ab52-29ee-455f-8efb-8d647fbd6c9c%40googlegroups.com?utm_medium=email&utm_source=footer>
> https://groups.google.com/d/msgid/puppet-users/1b36ab52-29ee-455f-8efb-8d647fbd6c9c%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/8d014b64-242d-4ef5-bc27-dfad20418c23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.