Antoine Benkemoun
2011-Aug-12 11:34 UTC
[Puppet Users] Accessing node variable in class and using it in a conditionnal
Hello, First of all, thank you for making the awesome piece of software that is Puppet. I have working with it for a week and I''m really liking what I''m seeing and I have been able to do quite a few tasks with ease. Currently, I am trying to configure Apache Virtual Hosts with Puppet and have been trying different things with little success. I have defined a node as the following : node ''test1.cob'' inherits serveurClient { $smcvhost = ''all'' } The serveurClient class includes the apache class. This works fine as Apache gets installed and all the configuration gets applied correctly, except the virtual hosts. The configuration relating to the virtual hosts is the following : class apache::config { File{ require => Class["apache::install"], notify => Class["apache::service"], ensure => present, owner => "www-data", group => "www-data", mode => 755 } ... if ( $smcvhost == ''belleville'' ) or ( $smcvhost == ''all'' ) { apache::smcvhost{''belleville'': client => ''belleville'', } } ... } The *apache::smcvhost* definition works correctly because if I specify it directly in the node without the condition, the virtual host gets created correctly with no errors. If I remove the if statement, it will also get created correctly. I have tried only specifying the second condition but that did not make it work. When this fails to be executed, I do not get any error. The puppet report just ignores this configuration part. I am thinking that this is some sort of variable scoping problem but from what I have read, this practice seems correct and I imagine puppet would give me some error if I tried to evaluate a non-existing variable. Thank you in advance for your help, Antoine -- 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.
piavlo
2011-Aug-12 20:31 UTC
[Puppet Users] Re: Accessing node variable in class and using it in a conditionnal
Does it work if you change to if ( $::smcvhost == ''belleville'' ) or ( $::smcvhost == ''all'' ) { ? Alex On Aug 12, 2:34 pm, Antoine Benkemoun <antoine.benkem...@gmail.com> wrote:> Hello, > > First of all, thank you for making the awesome piece of software that is > Puppet. I have working with it for a week and I''m really liking what I''m > seeing and I have been able to do quite a few tasks with ease. Currently, I > am trying to configure Apache Virtual Hosts with Puppet and have been trying > different things with little success. > > I have defined a node as the following : > > node ''test1.cob'' inherits serveurClient { > $smcvhost = ''all'' > } > > The serveurClient class includes the apache class. This works fine as Apache > gets installed and all the configuration gets applied correctly, except the > virtual hosts. > > The configuration relating to the virtual hosts is the following : > > class apache::config { > File{ > require => Class["apache::install"], > notify => Class["apache::service"], > ensure => present, > owner => "www-data", > group => "www-data", > mode => 755 > } > ... > if ( $smcvhost == ''belleville'' ) or ( $smcvhost == ''all'' ) { > apache::smcvhost{''belleville'': > client => ''belleville'', > } > } > ... > } > > The *apache::smcvhost* definition works correctly because if I specify it > directly in the node without the condition, the virtual host gets created > correctly with no errors. If I remove the if statement, it will also get > created correctly. I have tried only specifying the second condition but > that did not make it work. > > When this fails to be executed, I do not get any error. The puppet report > just ignores this configuration part. > > I am thinking that this is some sort of variable scoping problem but from > what I have read, this practice seems correct and I imagine puppet would > give me some error if I tried to evaluate a non-existing variable. > > Thank you in advance for your help, > > Antoine-- 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.
Scott Smith
2011-Aug-12 20:38 UTC
Re: [Puppet Users] Accessing node variable in class and using it in a conditionnal
I experienced something similar to this. Try it without quoting the RHS. E.g if $smcvhost = belleville { } Also, what you are doing is code smell. On Fri, Aug 12, 2011 at 4:34 AM, Antoine Benkemoun < antoine.benkemoun@gmail.com> wrote:> Hello, > > First of all, thank you for making the awesome piece of software that is > Puppet. I have working with it for a week and I''m really liking what I''m > seeing and I have been able to do quite a few tasks with ease. Currently, I > am trying to configure Apache Virtual Hosts with Puppet and have been trying > different things with little success. > > I have defined a node as the following : > > node ''test1.cob'' inherits serveurClient { > $smcvhost = ''all'' > } > > The serveurClient class includes the apache class. This works fine as > Apache gets installed and all the configuration gets applied correctly, > except the virtual hosts. > > The configuration relating to the virtual hosts is the following : > > class apache::config { > File{ > require => Class["apache::install"], > notify => Class["apache::service"], > ensure => present, > owner => "www-data", > group => "www-data", > mode => 755 > } > ... > if ( $smcvhost == ''belleville'' ) or ( $smcvhost == ''all'' ) { > apache::smcvhost{''belleville'': > client => ''belleville'', > } > } > ... > } > > The *apache::smcvhost* definition works correctly because if I specify it > directly in the node without the condition, the virtual host gets created > correctly with no errors. If I remove the if statement, it will also get > created correctly. I have tried only specifying the second condition but > that did not make it work. > > When this fails to be executed, I do not get any error. The puppet report > just ignores this configuration part. > > I am thinking that this is some sort of variable scoping problem but from > what I have read, this practice seems correct and I imagine puppet would > give me some error if I tried to evaluate a non-existing variable. > > Thank you in advance for your help, > > Antoine > > -- > 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.
Antoine Benkemoun
2011-Aug-13 07:48 UTC
Re: [Puppet Users] Accessing node variable in class and using it in a conditionnal
Hello, I have actually found out that the problem is variable scoping. The explanation has been given here : http://serverfault.com/questions/300446/accessing-node-variable-in-class-and-using-it-in-a-conditionnal Thank you for your help anyways :) Antoine On Fri, Aug 12, 2011 at 10:38 PM, Scott Smith <scott@ohlol.net> wrote:> I experienced something similar to this. Try it without quoting the RHS. > E.g > > if $smcvhost = belleville { > } > > Also, what you are doing is code smell. > > On Fri, Aug 12, 2011 at 4:34 AM, Antoine Benkemoun < > antoine.benkemoun@gmail.com> wrote: > >> Hello, >> >> First of all, thank you for making the awesome piece of software that is >> Puppet. I have working with it for a week and I''m really liking what I''m >> seeing and I have been able to do quite a few tasks with ease. Currently, I >> am trying to configure Apache Virtual Hosts with Puppet and have been trying >> different things with little success. >> >> I have defined a node as the following : >> >> node ''test1.cob'' inherits serveurClient { >> $smcvhost = ''all'' >> } >> >> The serveurClient class includes the apache class. This works fine as >> Apache gets installed and all the configuration gets applied correctly, >> except the virtual hosts. >> >> The configuration relating to the virtual hosts is the following : >> >> class apache::config { >> File{ >> require => Class["apache::install"], >> notify => Class["apache::service"], >> ensure => present, >> owner => "www-data", >> group => "www-data", >> mode => 755 >> } >> ... >> if ( $smcvhost == ''belleville'' ) or ( $smcvhost == ''all'' ) { >> apache::smcvhost{''belleville'': >> client => ''belleville'', >> } >> } >> ... >> } >> >> The *apache::smcvhost* definition works correctly because if I specify it >> directly in the node without the condition, the virtual host gets created >> correctly with no errors. If I remove the if statement, it will also get >> created correctly. I have tried only specifying the second condition but >> that did not make it work. >> >> When this fails to be executed, I do not get any error. The puppet report >> just ignores this configuration part. >> >> I am thinking that this is some sort of variable scoping problem but from >> what I have read, this practice seems correct and I imagine puppet would >> give me some error if I tried to evaluate a non-existing variable. >> >> Thank you in advance for your help, >> >> Antoine >> >> -- >> 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. >-- 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.