Markus Rekkenbeil
2012-Jul-25 15:47 UTC
[Puppet Users] manifest variable with sed - problem
Hello, i have a problem in my sudo manifest file, because in the variable $name comes sometimes usernames like user.lastname, but i need for sudo (includedir */etc/sudoers.d/*) file names with no dots (like user_lastname). I need a new variable, where is the dots change by underscores. My first try was like this, but it isn''t working well. $name_underscore = "`echo $name | sed ''s/\./_/g''`" file { "*/etc/sudoers.d/*${name_underscore}": mode => 440, owner => "root", group => "root", content => template("sudo/sudo.erb"), } Please can anyone help me with my problem? Best regards, Markus Rekkenbeil -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/5WXIuAeLgmkJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Christopher Wood
2012-Jul-25 16:04 UTC
Re: [Puppet Users] manifest variable with sed - problem
On Wed, Jul 25, 2012 at 08:47:14AM -0700, Markus Rekkenbeil wrote:> Hello, > > i have a problem in my sudo manifest file, because in the variable $name > comes sometimes usernames like user.lastname, but i need for sudo > (includedir /etc/sudoers.d/) file names with no dots (like user_lastname). > > I need a new variable, where is the dots change by underscores. > > > My first try was like this, but it isn''t working well. > > $name_underscore = "`echo $name | sed ''s/\./_/g''`"The variable $name is reserved for use as as the namevar, so you''ll have to use something else as a variable name. http://docs.puppetlabs.com/guides/language_guide.html You could use an inline template to run the substitution via ruby. Example: $java_home = inline_template(''<%= /jre-([0-9])u([0-9]+)/.match(name); p = "/opt/jre1." + $1 + ".0_" + $2 %>'') So for you, something like this (warning, untested): $username_nous = inline_template(''<%= username.gsub(/\./, "_") %>'') Also see: http://www.ruby-doc.org/core-1.8.7/String.html> file { "/etc/sudoers.d/${name_underscore}": > mode => 440, > owner => "root", > group => "root", > content => template("sudo/sudo.erb"), > } > > Please can anyone help me with my problem? > > Best regards, > > Markus Rekkenbeil > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To view this discussion on the web visit > [1]https://groups.google.com/d/msg/puppet-users/-/5WXIuAeLgmkJ. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > > References > > Visible links > 1. https://groups.google.com/d/msg/puppet-users/-/5WXIuAeLgmkJ-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Kinzel, David
2012-Jul-25 16:43 UTC
RE: [Puppet Users] manifest variable with sed - problem
>From: puppet-users@googlegroups.com [mailto:puppet-users@googlegroups.com] >On Behalf Of Christopher Wood[snip]>You could use an inline template to run the substitution via ruby. Example: > >$java_home = inline_template(''<%= /jre-([0-9])u([0-9]+)/.match(name); p >"/opt/jre1." + $1 + ".0_" + $2 %>'') > >So for you, something like this (warning, untested): > >$username_nous = inline_template(''<%= username.gsub(/\./, "_") %>'')regsubst might be easier to use. $new = regsubst($old, ''foo'', ''bar'') This email communication and any files transmitted with it may contain confidential and or proprietary information and is provided for the use of the intended recipient only. Any review, retransmission or dissemination of this information by anyone other than the intended recipient is prohibited. If you receive this email in error, please contact the sender and delete this communication and any copies immediately. Thank you. http://www.encana.com -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Christopher Wood
2012-Jul-25 16:59 UTC
Re: [Puppet Users] manifest variable with sed - problem
On Wed, Jul 25, 2012 at 04:43:31PM +0000, Kinzel, David wrote:> >From: puppet-users@googlegroups.com [mailto:puppet-users@googlegroups.com] > >On Behalf Of Christopher Wood > > [snip] > > >You could use an inline template to run the substitution via ruby. Example: > > > >$java_home = inline_template(''<%= /jre-([0-9])u([0-9]+)/.match(name); p > >"/opt/jre1." + $1 + ".0_" + $2 %>'') > > > >So for you, something like this (warning, untested): > > > >$username_nous = inline_template(''<%= username.gsub(/\./, "_") %>'') > > > regsubst might be easier to use. > > $new = regsubst($old, ''foo'', ''bar'')My experience has that it''s easier until I need extra processing, like in the java_home example above. (I often do.) Good point though.> This email communication and any files transmitted with it may contain > confidential and or proprietary information and is provided for the use of the > intended recipient only. Any review, retransmission or dissemination of this > information by anyone other than the intended recipient is prohibited. If you > receive this email in error, please contact the sender and delete this > communication and any copies immediately. Thank you. > > http://www.encana.com > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > 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 puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.