Hello, I created puppet class and I want the file operation to be executed on all servers but not on server with hostname "''server1.domain.com". I tried this class, but it does not work. Is there any other way? Thanks class test { if $hostname != ''server1.domain.com'' { file { "/etc/ntp.conf": owner => root, group => root, mode => 644, source => "puppet:///files/server/ntp.conf", } } } -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Oct 11, 2013, at 5:48 AM, Jakub Bittner <rexcze@gmail.com> wrote:> Hello, > > I created puppet class and I want the file operation to be executed on all servers but not on server with hostname "''server1.domain.com". I tried this class, but it does not work. Is there any other way? Thanks > > > class test { > if $hostname != ''server1.domain.com'' { > file { "/etc/ntp.conf": > owner => root, > group => root, > mode => 644, > source => "puppet:///files/server/ntp.conf", > } > } > } >You have a couple errors in your if statement. For comparing a literal string, you need to use double-equals in your test: if $hostname == ''server1.domain.com'' { ... } For a regex match, you''d use the equal-tilde: if $hostname =~ /^server/ { ... } To negate a match, you put the not (!) in front of the entire comparison, e.g. if ! $hostname == ''server1.domain.com'' { ... } I like to add parentheses around my comparisons for visual clarity: if ( $hostname =~ /^server/ ) and ! ( $virtual == ''vmware'' ) { ... } -- Peter Bukowinski -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Peter Bukowinski [11.10.2013 14:39]:> On Oct 11, 2013, at 5:48 AM, Jakub Bittner <rexcze@gmail.com> wrote: > >> Hello, >> >> I created puppet class and I want the file operation to be executed on all servers but not on server with hostname "''server1.domain.com". I tried this class, but it does not work. Is there any other way? Thanks >> >> >> class test { >> if $hostname != ''server1.domain.com'' { >> file { "/etc/ntp.conf": >> owner => root, >> group => root, >> mode => 644, >> source => "puppet:///files/server/ntp.conf", >> } >> } >> } >> > > You have a couple errors in your if statement. For comparing a literal string, you need to use double-equals in your test: > > if $hostname == ''server1.domain.com'' { ... } > > For a regex match, you''d use the equal-tilde: > > if $hostname =~ /^server/ { ... } > > To negate a match, you put the not (!) in front of the entire comparison, e.g. > > if ! $hostname == ''server1.domain.com'' { ... } > > I like to add parentheses around my comparisons for visual clarity: > > if ( $hostname =~ /^server/ ) and ! ( $virtual == ''vmware'' ) { ... } >I do not see "a couple of errors". But I''m a novice, so you can enlarge my knowledge easily ;-) You show only one error by mentioning that the if statement may not have an inequality sign: "To negate a match, you put the not (!) in front of the entire comparison". Where can I find this in the puppet language description? First, I looked at <http://docs.puppetlabs.com/puppet/3/reference/lang_conditional.html#if-statements>. Under the caption "Conditions" I find - among others - "Expressions". So I follow that link, and on the linked page under <http://docs.puppetlabs.com/puppet/3/reference/lang_expressions.html#non-equality> I find the != operator. I do not find any hint that one has to prepend the nagation to the whole statement. In the contrary, in the "Syntax" section I see a sample for a comparison with an inequality sign: "($operatingsystem != ''Solaris'')". Where do I find that != is not allowed in this case? BTW, I''d never write a class like that, I''d rather use different node declarations... ;-) Regards, Werner -- -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Oct 11, 2013, at 9:06 AM, Werner Flamme <werner.flamme@ufz.de> wrote:> Peter Bukowinski [11.10.2013 14:39]: >> On Oct 11, 2013, at 5:48 AM, Jakub Bittner <rexcze@gmail.com> wrote: >> >>> Hello, >>> >>> I created puppet class and I want the file operation to be executed on all servers but not on server with hostname "''server1.domain.com". I tried this class, but it does not work. Is there any other way? Thanks >>> >>> >>> class test { >>> if $hostname != ''server1.domain.com'' { >>> file { "/etc/ntp.conf": >>> owner => root, >>> group => root, >>> mode => 644, >>> source => "puppet:///files/server/ntp.conf", >>> } >>> } >>> } >>> >> >> You have a couple errors in your if statement. For comparing a literal string, you need to use double-equals in your test: >> >> if $hostname == ''server1.domain.com'' { ... } >> >> For a regex match, you''d use the equal-tilde: >> >> if $hostname =~ /^server/ { ... } >> >> To negate a match, you put the not (!) in front of the entire comparison, e.g. >> >> if ! $hostname == ''server1.domain.com'' { ... } >> >> I like to add parentheses around my comparisons for visual clarity: >> >> if ( $hostname =~ /^server/ ) and ! ( $virtual == ''vmware'' ) { ... } >> > > I do not see "a couple of errors". But I''m a novice, so you can enlarge > my knowledge easily ;-) > > You show only one error by mentioning that the if statement may not have > an inequality sign: "To negate a match, you put the not (!) in front of > the entire comparison". Where can I find this in the puppet language > description? > > First, I looked at > <http://docs.puppetlabs.com/puppet/3/reference/lang_conditional.html#if-statements>. > Under the caption "Conditions" I find - among others - "Expressions". So > I follow that link, and on the linked page under > <http://docs.puppetlabs.com/puppet/3/reference/lang_expressions.html#non-equality> > I find the != operator. I do not find any hint that one has to prepend > the nagation to the whole statement. In the contrary, in the "Syntax" > section I see a sample for a comparison with an inequality sign: > "($operatingsystem != ''Solaris'')". > > Where do I find that != is not allowed in this case? > > BTW, I''d never write a class like that, I''d rather use different node > declarations... ;-) > > Regards, > WernerI''ve been using the convention where the not (!) is separate from the equals sign and it works well for me, so I suspect your only error was using a single equal sign rather than a the required double. -- Peter -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Peter Bukowinski [11.10.2013 15:57]:> On Oct 11, 2013, at 9:06 AM, Werner Flamme <werner.flamme@ufz.de> wrote: > >> Peter Bukowinski [11.10.2013 14:39]: >>> On Oct 11, 2013, at 5:48 AM, Jakub Bittner <rexcze@gmail.com> wrote: >>> >>>> Hello, >>>> >>>> I created puppet class and I want the file operation to be executed on all servers but not on server with hostname "''server1.domain.com". I tried this class, but it does not work. Is there any other way? Thanks >>>> >>>> >>>> class test { >>>> if $hostname != ''server1.domain.com'' { >>>> file { "/etc/ntp.conf": >>>> owner => root, >>>> group => root, >>>> mode => 644, >>>> source => "puppet:///files/server/ntp.conf", >>>> } >>>> } >>>> } >>>> >>> >>> You have a couple errors in your if statement. For comparing a literal string, you need to use double-equals in your test: >>> >>> if $hostname == ''server1.domain.com'' { ... } >>> >>> For a regex match, you''d use the equal-tilde: >>> >>> if $hostname =~ /^server/ { ... } >>> >>> To negate a match, you put the not (!) in front of the entire comparison, e.g. >>> >>> if ! $hostname == ''server1.domain.com'' { ... } >>> >>> I like to add parentheses around my comparisons for visual clarity: >>> >>> if ( $hostname =~ /^server/ ) and ! ( $virtual == ''vmware'' ) { ... } >>> >> >> I do not see "a couple of errors". But I''m a novice, so you can enlarge >> my knowledge easily ;-) >> >> You show only one error by mentioning that the if statement may not have >> an inequality sign: "To negate a match, you put the not (!) in front of >> the entire comparison". Where can I find this in the puppet language >> description? >> >> First, I looked at >> <http://docs.puppetlabs.com/puppet/3/reference/lang_conditional.html#if-statements>. >> Under the caption "Conditions" I find - among others - "Expressions". So >> I follow that link, and on the linked page under >> <http://docs.puppetlabs.com/puppet/3/reference/lang_expressions.html#non-equality> >> I find the != operator. I do not find any hint that one has to prepend >> the nagation to the whole statement. In the contrary, in the "Syntax" >> section I see a sample for a comparison with an inequality sign: >> "($operatingsystem != ''Solaris'')". >> >> Where do I find that != is not allowed in this case? >> >> BTW, I''d never write a class like that, I''d rather use different node >> declarations... ;-) >> >> Regards, >> Werner > > > I''ve been using the convention where the not (!) is separate from the equals sign and it works well for me, so I suspect your only error was using a single equal sign rather than a the required double. >I''m not Jakub (the OP), it is not my problem. I''m only the one who wanted to know where the "couple of errors" are. Regards, Werner -- Werner Flamme, Abt. WKDV Helmholtz-Zentrum für Umweltforschung GmbH - UFZ Helmholtz Centre for Environmental Research - UFZ Permoserstr. 15 - 04318 Leipzig / Germany Tel./phone: +49 341 235-1921 - Fax +49 341 235-451921 Information nach §§ 37a HGB, 35a GmbHG: Sitz der Gesellschaft: Leipzig Registergericht: Amtsgericht Leipzig, Handelsregister Nr. B 4703 Vorsitzender des Aufsichtsrats: MinDirig Wilfried Kraus Wissenschaftlicher Geschäftsführer: Prof. Dr. Georg Teutsch (Scientific Managing Director) Administrative Geschäftsführerin: Dr. Heike Graßmann (Administrative Managing Director) -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Guys, check this out: http://docs.puppetlabs.com/puppet/3/reference/lang_expressions.html Either way should work. @Jakub, 2 things I see here: * you should generally make sure to use the right scope in your variables. I''m assuming from your code that you want the global facter variable hostname in which case you should use in in a global scope: $::hostname. * Hostname normally only gives you the first part of the fully qualified name in your case that would be ''server1''. if you need the fully qualified name for a server with the domain you usually need to use: $::fqdn Also you can easily check situations like this with a notice(http://docs.puppetlabs.com/references/latest/function.html#notice) or notify(http://docs.puppetlabs.com/references/latest/type.html#notify) statement Hope this helps! -Bernd On Friday, October 11, 2013 6:59:10 AM UTC-7, Werner Flamme wrote:> > Peter Bukowinski [11.10.2013 15:57]: > > On Oct 11, 2013, at 9:06 AM, Werner Flamme <werner...@ufz.de<javascript:>> > wrote: > > > >> Peter Bukowinski [11.10.2013 14:39]: > >>> On Oct 11, 2013, at 5:48 AM, Jakub Bittner <rex...@gmail.com<javascript:>> > wrote: > >>> > >>>> Hello, > >>>> > >>>> I created puppet class and I want the file operation to be executed > on all servers but not on server with hostname "''server1.domain.com". I > tried this class, but it does not work. Is there any other way? Thanks > >>>> > >>>> > >>>> class test { > >>>> if $hostname != ''server1.domain.com'' { > >>>> file { "/etc/ntp.conf": > >>>> owner => root, > >>>> group => root, > >>>> mode => 644, > >>>> source => "puppet:///files/server/ntp.conf", > >>>> } > >>>> } > >>>> } > >>>> > >>> > >>> You have a couple errors in your if statement. For comparing a literal > string, you need to use double-equals in your test: > >>> > >>> if $hostname == ''server1.domain.com'' { ... } > >>> > >>> For a regex match, you''d use the equal-tilde: > >>> > >>> if $hostname =~ /^server/ { ... } > >>> > >>> To negate a match, you put the not (!) in front of the entire > comparison, e.g. > >>> > >>> if ! $hostname == ''server1.domain.com'' { ... } > >>> > >>> I like to add parentheses around my comparisons for visual clarity: > >>> > >>> if ( $hostname =~ /^server/ ) and ! ( $virtual == ''vmware'' ) { ... > } > >>> > >> > >> I do not see "a couple of errors". But I''m a novice, so you can enlarge > >> my knowledge easily ;-) > >> > >> You show only one error by mentioning that the if statement may not > have > >> an inequality sign: "To negate a match, you put the not (!) in front of > >> the entire comparison". Where can I find this in the puppet language > >> description? > >> > >> First, I looked at > >> < > http://docs.puppetlabs.com/puppet/3/reference/lang_conditional.html#if-statements>. > > >> Under the caption "Conditions" I find - among others - "Expressions". > So > >> I follow that link, and on the linked page under > >> < > http://docs.puppetlabs.com/puppet/3/reference/lang_expressions.html#non-equality> > > >> I find the != operator. I do not find any hint that one has to prepend > >> the nagation to the whole statement. In the contrary, in the "Syntax" > >> section I see a sample for a comparison with an inequality sign: > >> "($operatingsystem != ''Solaris'')". > >> > >> Where do I find that != is not allowed in this case? > >> > >> BTW, I''d never write a class like that, I''d rather use different node > >> declarations... ;-) > >> > >> Regards, > >> Werner > > > > > > I''ve been using the convention where the not (!) is separate from the > equals sign and it works well for me, so I suspect your only error was > using a single equal sign rather than a the required double. > > > > I''m not Jakub (the OP), it is not my problem. > > I''m only the one who wanted to know where the "couple of errors" are. > > Regards, > Werner > > -- > Werner Flamme, Abt. WKDV > Helmholtz-Zentrum f�r Umweltforschung GmbH - UFZ > Helmholtz Centre for Environmental Research - UFZ > Permoserstr. 15 - 04318 Leipzig / Germany > Tel./phone: +49 341 235-1921 - Fax +49 341 235-451921 > Information nach �� 37a HGB, 35a GmbHG: > Sitz der Gesellschaft: Leipzig > Registergericht: Amtsgericht Leipzig, Handelsregister Nr. B 4703 > Vorsitzender des Aufsichtsrats: MinDirig Wilfried Kraus > Wissenschaftlicher Gesch�ftsf�hrer: Prof. Dr. Georg Teutsch > (Scientific Managing Director) > Administrative Gesch�ftsf�hrerin: Dr. Heike Gra�mann > (Administrative Managing Director) >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Friday, October 11, 2013 8:59:10 AM UTC-5, Werner Flamme wrote:> > I''m not Jakub (the OP), it is not my problem. > > I''m only the one who wanted to know where the "couple of errors" are. > >Peter was mistaken. There are no actual errors in the OP''s manifest, and it might work in some environments. In particular, the operator "!=" performs a boolean test for non-equality, just as the OP expected it to do. The reason it didn''t work for him is almost surely what Bernd pointed out: the $::hostname fact usually contains only a local name, not a fully-qualified domain name. John -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.