On 2019-04-07 14:47, KRouth Clinipace 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


Well, functions are ordinary on the compiling side. If you can figure out what to do when compiling that is preferable.

Alternatively, you can call functions on the agent side by using a Deferred value that delays the call and makes it on the agent side. You need Puppet 6 to be able to do that. (And if you need custom logic you can write your own function in Ruby using the function API).

To answer if there is a better way we need to understand what you are actually doing (I did not try to make sense of what your exec and the perl logic actually does...

Best
- henrik

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 <http://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
    marley...@gmail.com <javascript:>

    2010/5/21 R.I.Pienaar <r...@devco.net <javascript:>>

         > 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
        <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 puppet...@googlegroups.com
        <javascript:>.
        To unsubscribe from this group, send email to
        puppet...@googlegroups.com <javascript:>.
        For more options, visit this group at
        http://groups.google.com/group/puppet-users?hl=en
        <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 puppet...@googlegroups.com
    <javascript:>.
    To unsubscribe from this group, send email to
    puppet...@googlegroups.com <javascript:>.
    For more options, visit this group at
    http://groups.google.com/group/puppet-users?hl=en
    <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 puppet-users+unsubscr...@googlegroups.com <mailto:puppet-users+unsubscr...@googlegroups.com>. 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.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/q8g3u8%24c1m%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to