Hi, Sorry if this is a basic question, but I can''t find the answer in the docs. I know about fully-qualified variables, but how can I reference a type that is defined in a different class, so I can require/subscribe it? In this simple example, what''s the right syntax for making goodbye.txt require hello.txt? class class1 { file { "hello.txt" } } class class2 { file { "goodbye.txt": require => File[''hello.txt''], } } Thanks, Jonathan -- 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.
On 08/24/2011 11:54 AM, Jonathan Gazeley wrote:> Hi, > > Sorry if this is a basic question, but I can''t find the answer in the > docs. I know about fully-qualified variables, but how can I reference a > type that is defined in a different class, so I can require/subscribe it? > > In this simple example, what''s the right syntax for making goodbye.txt > require hello.txt? > > class class1 { > file { "hello.txt" } > } > > class class2 { > file { "goodbye.txt": > require => File[''hello.txt''], > } > } > > > Thanks, > Jonathan >class class1 { file { hello: path => ''hello.txt'', } } class class2 { file { goodbye: path => ''goodbye.txt'', require => File[class1::hello], } } (untested!) -- 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.
Jonathan Gazeley
2011-Aug-24 12:56 UTC
Re: [Puppet Users] Requiring types in other classes
On 24/08/11 11:13, Martin Alfke wrote:> On 08/24/2011 11:54 AM, Jonathan Gazeley wrote: >> Hi, >> >> Sorry if this is a basic question, but I can''t find the answer in the >> docs. I know about fully-qualified variables, but how can I reference a >> type that is defined in a different class, so I can require/subscribe it? >> >> In this simple example, what''s the right syntax for making goodbye.txt >> require hello.txt? >> >> class class1 { >> file { "hello.txt" } >> } >> >> class class2 { >> file { "goodbye.txt": >> require => File[''hello.txt''], >> } >> } >> >> >> Thanks, >> Jonathan >> > > class class1 { > file { hello: > path => ''hello.txt'', > } > } > > class class2 { > file { goodbye: > path => ''goodbye.txt'', > require => File[class1::hello], > } > } > > (untested!) >Hmm, this is what I tried before mailing the list, and I still can''t get it to work. If it makes any difference, my classes are nested. mysql::mmm::common mysql::mmm::agent class mysql::mmm::agent { include mysql::mmm::common package { "mysql-mmm-agent": ensure => installed, } file {"mmm_agent.conf": name => "/etc/mysql-mmm/mmm_agent.conf", mode => 640, owner => "root", group => "root", content => template("/etc/puppet/modules/mysql/files/mmm_agent.conf.erb"), require => Package["mysql-mmm-agent"], notify => Service["mysql-mmm-agent"], } service {"mysql-mmm-agent": require => [ Package[''mysql-mmm-agent''], File[''mmm_agent.conf'', ''mmm_common.conf''], ], ensure => running, enable => true, hasstatus => true, hasrestart => true, subscribe => File["common::mmm_common.conf", ''mmm_agent.conf''], } } class mysql::mmm::common { package { "mysql-mmm": ensure => installed, } file { "mmm_common.conf": name => "/etc/mysql-mmm/mmm_common.conf", mode => 640, owner => "root", group => "root", source => "puppet:///modules/mysql/mmm_common.conf", require => Package["mysql-mmm"], } } Using this manifest throws this error: err: Could not run Puppet configuration client: Could not find dependency File[mysql::mmm::common::mmm-common.conf] for Service[mysql-mmm-agent] at /etc/puppet/modules/mysql/manifests/init.pp:159 Any ideas? Thanks, Jonathan -- 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.
On Aug 24, 4:54 am, Jonathan Gazeley <jonathan.gaze...@bristol.ac.uk> wrote:> Hi, > > Sorry if this is a basic question, but I can''t find the answer in the > docs. I know about fully-qualified variables, but how can I reference a > type that is defined in a different class, so I can require/subscribe it? > > In this simple example, what''s the right syntax for making goodbye.txt > require hello.txt? > > class class1 { > file { "hello.txt" } > > } > > class class2 { > file { "goodbye.txt": > require => File[''hello.txt''], > } > > }The word you are looking for is "resource," not "type." The latter is more likely to make people think of user-defined resource types, such as are declared via the "define" statement. The answer is that resource titles and names are global (and must be globally unique) in nodes'' catalogs, therefore you don''t have to use any special syntax to reference a resource from outside the scope where it is declared. You do, however, need to ensure that the declaration is visible at the point of reference. As long as you''re not using parameterized classes, the best way to do that is via the "include" statement, like so: class class1 { file { "hello.txt" } } class class2 { # Include the class declaring File[''hello.txt''] include "class1" file { "goodbye.txt": require => File[''hello.txt''] } } Do remember that Puppet''s "include" statement is *not* analogous to, for example, the C peprocessor''s "#include" directive. It does not cause any code interpolation; instead, "include" tells Puppet that the specified class must be included in the current node''s catalog. John -- 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.
Jonathan Gazeley
2011-Aug-24 13:15 UTC
Re: [Puppet Users] Re: Requiring types in other classes
On 24/08/11 14:09, jcbollinger wrote:> > > On Aug 24, 4:54 am, Jonathan Gazeley<jonathan.gaze...@bristol.ac.uk> > wrote: >> Hi, >> >> Sorry if this is a basic question, but I can''t find the answer in the >> docs. I know about fully-qualified variables, but how can I reference a >> type that is defined in a different class, so I can require/subscribe it? >> >> In this simple example, what''s the right syntax for making goodbye.txt >> require hello.txt? >> >> class class1 { >> file { "hello.txt" } >> >> } >> >> class class2 { >> file { "goodbye.txt": >> require => File[''hello.txt''], >> } >> >> } > > > The word you are looking for is "resource," not "type." The latter is > more likely to make people think of user-defined resource types, such > as are declared via the "define" statement. > > The answer is that resource titles and names are global (and must be > globally unique) in nodes'' catalogs, therefore you don''t have to use > any special syntax to reference a resource from outside the scope > where it is declared. > > You do, however, need to ensure that the declaration is visible at the > point of reference. As long as you''re not using parameterized > classes, the best way to do that is via the "include" statement, like > so: > > class class1 { > file { "hello.txt" } > } > > > class class2 { > # Include the class declaring File[''hello.txt''] > include "class1" > > file { "goodbye.txt": > require => File[''hello.txt''] > } > } > > > Do remember that Puppet''s "include" statement is *not* analogous to, > for example, the C peprocessor''s "#include" directive. It does not > cause any code interpolation; instead, "include" tells Puppet that the > specified class must be included in the current node''s catalog. > > > John >Thanks for your excellent response. I hadn''t realised that resource names were global, nor that "include" behaves differently from that of the C preprocessor. Win on both counts - I''ve got my manifest working. Thanks a lot, Jonathan -- 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.
Hi, Underscore instead of dash? Den On 24/08/2011, at 22:56, Jonathan Gazeley <jonathan.gazeley@bristol.ac.uk> wrote:> On 24/08/11 11:13, Martin Alfke wrote: >> On 08/24/2011 11:54 AM, Jonathan Gazeley wrote: >>> Hi, >>> >>> Sorry if this is a basic question, but I can''t find the answer in the >>> docs. I know about fully-qualified variables, but how can I reference a >>> type that is defined in a different class, so I can require/subscribe it? >>> >>> In this simple example, what''s the right syntax for making goodbye.txt >>> require hello.txt? >>> >>> class class1 { >>> file { "hello.txt" } >>> } >>> >>> class class2 { >>> file { "goodbye.txt": >>> require => File[''hello.txt''], >>> } >>> } >>> >>> >>> Thanks, >>> Jonathan >>> >> >> class class1 { >> file { hello: >> path => ''hello.txt'', >> } >> } >> >> class class2 { >> file { goodbye: >> path => ''goodbye.txt'', >> require => File[class1::hello], >> } >> } >> >> (untested!) >> > > > Hmm, this is what I tried before mailing the list, and I still can''t get it to work. > > If it makes any difference, my classes are nested. > > mysql::mmm::common > mysql::mmm::agent > > > > class mysql::mmm::agent { > include mysql::mmm::common > > package { "mysql-mmm-agent": > ensure => installed, > } > > file {"mmm_agent.conf": > name => "/etc/mysql-mmm/mmm_agent.conf", > mode => 640, owner => "root", group => "root", > content => template("/etc/puppet/modules/mysql/files/mmm_agent.conf.erb"), > require => Package["mysql-mmm-agent"], > notify => Service["mysql-mmm-agent"], > } > > service {"mysql-mmm-agent": > require => [ Package[''mysql-mmm-agent''], File[''mmm_agent.conf'', ''mmm_common.conf''], ], > ensure => running, > enable => true, > hasstatus => true, > hasrestart => true, > subscribe => File["common::mmm_common.conf", ''mmm_agent.conf''], > } > } > > > class mysql::mmm::common { > package { "mysql-mmm": > ensure => installed, > } > > file { "mmm_common.conf": > name => "/etc/mysql-mmm/mmm_common.conf", > mode => 640, owner => "root", group => "root", > source => "puppet:///modules/mysql/mmm_common.conf", > require => Package["mysql-mmm"], > } > } > > > Using this manifest throws this error: > > err: Could not run Puppet configuration client: Could not find dependency File[mysql::mmm::common::mmm-common.conf] for Service[mysql-mmm-agent] at /etc/puppet/modules/mysql/manifests/init.pp:159 > > Any ideas? > > Thanks, > Jonathan > > -- > 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.