It looks like what you're trying to do is inline editing of /etc/bashrc,
but still let people poke at it themselves. That's a fragile position to be
in. For example, given your regex solution, what's to stop someone from
doing something like innocently defining their $PS1 iteratively? Something
like this made up example:

PS1=$(run some command)
> PS1="$(run some other command)/${PS1}"
> export PS1="(${PS1}) \u@\h: \W: "


Or maybe they want to set another variable, maybe something like:

export UPS1_STATE="some such or other"


You'll end up with garbled variables at best, or a crashed script and then
complaints that you broke their system. (maybe you'll even get lucky and
they'll be tickets! lol)

Instead, a far far far more maintainable pattern is for you to flat out own
/etc/bashrc, but to source a second  /etc/bashrc.local user editable file
from within. That lets you manage it as a template which will give you a
known and repeatable output, and let the users do their own customization
in a place that they own, meaning that they also own any failures they
create.


On Mon, Apr 8, 2019 at 10:23 AM KRouth Clinipace <[email protected]>
wrote:

> Question - is it possible to use the puppet regsubst function in place of
> the exec used here (to save spawning a new shell process) ?
> kevin
>
> On Friday, May 21, 2010 at 10:28:58 PM UTC-4, Marley Bacelar wrote:
>>
>> Nice... I solved my probleman using the:
>>
>> define replace($file, $pattern, $replacement) {
>>   exec { "/usr/bin/perl -pi -e 's/$pattern/$replacement/' '$file'":
>>       onlyif => "/usr/bin/perl -ne 'BEGIN { \$ret = 1; } \$ret = 0 if
>> /$pattern/ && ! /$replacement/ ; END { exit \$ret; }' '$file'",
>>    }
>> }
>>
>> Then i my class used:
>>
>> replace { "/etc/bashrc":
>>    file => "/etc/bashrc",
>>    pattern => "PS1",
>>    replacement => "PS1 DOMAINA.COM"
>> }
>> Worked perfectly... Know i will see the other options proposed here.
>> Thank you evry much guys
>>
>> --
>> Marley Bacelar
>> Project Fedora Ambassador
>> VCP, VSP. VTSP., ITILF, IBM 000-076, IBM 000-330, IBM 000-331
>> [email protected]
>>
>> 2010/5/21 R.I.Pienaar <[email protected]>
>>
>>> > The vast majority of our text replacement work we do is for files that
>>> > have simple key/value pairs with an assignment operator.
>>> >
>>> >
>>> > foo=bar
>>> > foo: bar
>>> >
>>> >
>>> > etc.
>>> >
>>> >
>>> > We occasionally stray outside this with a regexp replacer, but I
>>> > totally agree with Daniel here, it's not the most robust thing in the
>>> > world.
>>> >
>>> >
>>> > Generally we do this because we want to allow people to customize
>>> > extra parts of their config files, and we've switched daemons entirely
>>> > for some services, simply based upon their ability to cope with a
>>> > parts.d directory or to have "include" directives of some kind.
>>> >
>>> >
>>> > That allows you to ship an absolute config with a default include that
>>> > people are free to modify.
>>> >
>>>
>>>
>>> fwiw, the newest version of my concat module supports symlinking into a
>>> concat file, so if you have a config file that you would like users to drop
>>> settings it and you want them to only do so in a very specific place in a
>>> file you can now achieve that by building your config file and including a
>>> user editable file right where you want it.
>>>
>>> Very nice feature to give users some rights without loosing control of
>>> the file or its structure.
>>>
>>> It wouldn't be too hard to extend it to make arbitrary user supplied .d
>>> directories for daemons that dont support those :)
>>>
>>> http://github.com/ripienaar/puppet-concat
>>>
>>>
>>> --
>>> R.I.Pienaar
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Puppet Users" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to [email protected]
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/puppet-users?hl=en.
>>>
>>>
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Puppet Users" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/puppet-users?hl=en.
>>
> --
> 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/efa23924-e6eb-4338-bdb6-648d01923cee%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/efa23924-e6eb-4338-bdb6-648d01923cee%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CACkW_L6i-jRvXg2XeMcc0N3LxxTzoRNnj9sxqRLOJ6-SL-E1Vw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to