Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
Great, It worked for me. Thanks Dylan, Reid and Michael. Appreciate all your help. Regards, Ganesh On Sat, Jun 20, 2015 at 2:21 PM, Dylan Ratcliffe dylan.ratcli...@puppetlabs.com wrote: I would use the value of the $title variable to ensure both that you can refer to the new_type resource and that it will have a unique title each time the defined type is called, to find out more check out this page, it has everything you need to know about writing a defined type: http://docs.puppetlabs.com/learning/definedtypes.html#title-and-name In terms of where this would go in your manifests: As long as your defined type is sitting in a file that follows the namespacing rules it will be accessible just like any other resource type: https://docs.puppetlabs.com/puppet/latest/reference/lang_namespaces.html On Sat, Jun 20, 2015 at 12:02 AM, Ganesh Nalawade ganesh...@gmail.com wrote: Thanks Dylan. This approach looks good as and users don't have to add file resource explicitly. define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], ---*'another_resource' must be a variable as it is title of new_type resource. How can i pass title of new_type as parameter?* } new_type { 'another_resource': parameter1 = $file_path, } } I am confused where to place new defined type manifest file. The new_type (netdev_group) can be referred here: https://github.com/ganeshnalawade/puppet-netdev-stdlib-junos/tree/master/lib/puppet/type On Fri, Jun 19, 2015 at 7:30 AM, Dylan Ratcliffe dylan.ratcli...@puppetlabs.com wrote: That's close, You don't need to set ensure on a defined type unless you have exposed that as a paremeter, and you do need to set ensure for that file. Going back to the original issue of accessing the parameter of one resource from another, i'll give a little example of how I envision it: define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], } new_type { 'another_resource': parameter1 = $file_path, } } In this case the new_type resource can have access to a parameter in the file resource because it was passed in as a parameter and as a result is a variable that we can use. If we wanted to actually use this type we would do so like this: new_type::something { 'any_title': file_path = '/foo/bar.html', } Does this make sense? On Thursday, 18 June 2015 15:14:17 UTC+10, ganesh634 wrote: @Reid: Agreed it make sense to reference another resource instead of path string. The links you shared are very helpful. Thanks!!! @Dylan: While going through defined types i came across vhost here: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp I am not very clear how can i use it in my case. If a new defined type is used say new_type::load as below will it work? # /etc/puppetlabs/puppet/modules/new_type/manifests/load.pp define new_type::load ($path, $template_path){ include new_type file { $path: content = template($template_path), notify = new_type[ ? ], - *how to pass 'sample' here? * } } #/etc/puppetlabs/puppet/manifest/site.pp node 'node_name' { $names = [ abc, xyz ] new_type::load {'sample': path = '/var/tmp/test.txt' template_path = 'new_type/test_template.erb', ensure = present } } #/etc/puppetlabs/puppet/modules/new_type/templates/test_template.erb % @names.each do |name| % Hi %= name %!!! % end % ~ On client run #cat /var/tmp/test.txt Hi abc!!! Hi xyz!!! new_type resource 'sample' should be notified every time contents of test.txt is modified. On Thu, Jun 18, 2015 at 3:48 AM, Dylan Ratcliffe dylan.r...@puppetlabs.com wrote: Assuming that the file and the new_type resource will always be together I would wrap them in a defined type and expose everything you need as parameters. That way both can have access to it without any hacky stuff. I'm not sure of your level of Puppet knowledge so if that makes no sense let me know and I will explain. On Thursday, 18 June 2015 02:16:11 UTC+10, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com wrote:
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
I would use the value of the $title variable to ensure both that you can refer to the new_type resource and that it will have a unique title each time the defined type is called, to find out more check out this page, it has everything you need to know about writing a defined type: http://docs.puppetlabs.com/learning/definedtypes.html#title-and-name In terms of where this would go in your manifests: As long as your defined type is sitting in a file that follows the namespacing rules it will be accessible just like any other resource type: https://docs.puppetlabs.com/puppet/latest/reference/lang_namespaces.html On Sat, Jun 20, 2015 at 12:02 AM, Ganesh Nalawade ganesh...@gmail.com wrote: Thanks Dylan. This approach looks good as and users don't have to add file resource explicitly. define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], ---*'another_resource' must be a variable as it is title of new_type resource. How can i pass title of new_type as parameter?* } new_type { 'another_resource': parameter1 = $file_path, } } I am confused where to place new defined type manifest file. The new_type (netdev_group) can be referred here: https://github.com/ganeshnalawade/puppet-netdev-stdlib-junos/tree/master/lib/puppet/type On Fri, Jun 19, 2015 at 7:30 AM, Dylan Ratcliffe dylan.ratcli...@puppetlabs.com wrote: That's close, You don't need to set ensure on a defined type unless you have exposed that as a paremeter, and you do need to set ensure for that file. Going back to the original issue of accessing the parameter of one resource from another, i'll give a little example of how I envision it: define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], } new_type { 'another_resource': parameter1 = $file_path, } } In this case the new_type resource can have access to a parameter in the file resource because it was passed in as a parameter and as a result is a variable that we can use. If we wanted to actually use this type we would do so like this: new_type::something { 'any_title': file_path = '/foo/bar.html', } Does this make sense? On Thursday, 18 June 2015 15:14:17 UTC+10, ganesh634 wrote: @Reid: Agreed it make sense to reference another resource instead of path string. The links you shared are very helpful. Thanks!!! @Dylan: While going through defined types i came across vhost here: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp I am not very clear how can i use it in my case. If a new defined type is used say new_type::load as below will it work? # /etc/puppetlabs/puppet/modules/new_type/manifests/load.pp define new_type::load ($path, $template_path){ include new_type file { $path: content = template($template_path), notify = new_type[ ? ], - *how to pass 'sample' here? * } } #/etc/puppetlabs/puppet/manifest/site.pp node 'node_name' { $names = [ abc, xyz ] new_type::load {'sample': path = '/var/tmp/test.txt' template_path = 'new_type/test_template.erb', ensure = present } } #/etc/puppetlabs/puppet/modules/new_type/templates/test_template.erb % @names.each do |name| % Hi %= name %!!! % end % ~ On client run #cat /var/tmp/test.txt Hi abc!!! Hi xyz!!! new_type resource 'sample' should be notified every time contents of test.txt is modified. On Thu, Jun 18, 2015 at 3:48 AM, Dylan Ratcliffe dylan.r...@puppetlabs.com wrote: Assuming that the file and the new_type resource will always be together I would wrap them in a defined type and expose everything you need as parameters. That way both can have access to it without any hacky stuff. I'm not sure of your level of Puppet knowledge so if that makes no sense let me know and I will explain. On Thursday, 18 June 2015 02:16:11 UTC+10, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify =
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
Is there a way to retrieve the parameter values of resource for previous client run during current execution of client. The reason for this question is how to handle scenario where path value of 'new_type' resource is changed to already existing file whose contents are not changed. In this case 'new_type' resource will not be notified. Sample example to explains this. *1st client run:* #/etc/puppet/manifests/site.pp $name = [ ge-1/2/4 ] new_type::something{ sample: path = /var/tmp/first_run.txt, template_path = new_type/test.erb, ensure= present, } *2nd client run:* #/etc/puppet/manifests/site.pp $name = [ ge-1/2/6 ] new_type::something{ sample: path = /var/tmp/second_run.txt, template_path = new_type/test.erb, ensure= present, } *3rd client run:* #/etc/puppet/manifests/site.pp $name = [ ge-1/2/4 ] new_type::something{ sample: path = /var/tmp/first_run.txt, template_path = new_type/test.erb, ensure= present, } 1st client run state is ge-1/2/4 2nd client run state is changed to ge-1/2/6 For 3rd client run state should again be ge-1/2/4 again but as file 'first_run.txt' is not changed it won't notify 'new_type' refresh hence state still remain ge-1/2/6 which is not expected. It seems way to identify 'path' parameter value change in 'new_type' is to retrieve its value from previous client run. On Saturday, 20 June 2015 14:21:06 UTC+5:30, Dylan Ratcliffe wrote: I would use the value of the $title variable to ensure both that you can refer to the new_type resource and that it will have a unique title each time the defined type is called, to find out more check out this page, it has everything you need to know about writing a defined type: http://docs.puppetlabs.com/learning/definedtypes.html#title-and-name In terms of where this would go in your manifests: As long as your defined type is sitting in a file that follows the namespacing rules it will be accessible just like any other resource type: https://docs.puppetlabs.com/puppet/latest/reference/lang_namespaces.html On Sat, Jun 20, 2015 at 12:02 AM, Ganesh Nalawade gane...@gmail.com javascript: wrote: Thanks Dylan. This approach looks good as and users don't have to add file resource explicitly. define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], ---*'another_resource' must be a variable as it is title of new_type resource. How can i pass title of new_type as parameter?* } new_type { 'another_resource': parameter1 = $file_path, } } I am confused where to place new defined type manifest file. The new_type (netdev_group) can be referred here: https://github.com/ganeshnalawade/puppet-netdev-stdlib-junos/tree/master/lib/puppet/type On Fri, Jun 19, 2015 at 7:30 AM, Dylan Ratcliffe dylan.r...@puppetlabs.com javascript: wrote: That's close, You don't need to set ensure on a defined type unless you have exposed that as a paremeter, and you do need to set ensure for that file. Going back to the original issue of accessing the parameter of one resource from another, i'll give a little example of how I envision it: define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], } new_type { 'another_resource': parameter1 = $file_path, } } In this case the new_type resource can have access to a parameter in the file resource because it was passed in as a parameter and as a result is a variable that we can use. If we wanted to actually use this type we would do so like this: new_type::something { 'any_title': file_path = '/foo/bar.html', } Does this make sense? On Thursday, 18 June 2015 15:14:17 UTC+10, ganesh634 wrote: @Reid: Agreed it make sense to reference another resource instead of path string. The links you shared are very helpful. Thanks!!! @Dylan: While going through defined types i came across vhost here: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp I am not very clear how can i use it in my case. If a new defined type is used say new_type::load as below will it work? # /etc/puppetlabs/puppet/modules/new_type/manifests/load.pp define new_type::load ($path, $template_path){ include new_type file { $path: content = template($template_path), notify = new_type[ ? ], - *how to pass 'sample' here? * } } #/etc/puppetlabs/puppet/manifest/site.pp node 'node_name' { $names = [ abc, xyz ] new_type::load {'sample': path = '/var/tmp/test.txt' template_path = 'new_type/test_template.erb', ensure = present } } #/etc/puppetlabs/puppet/modules/new_type/templates/test_template.erb % @names.each do |name| % Hi %= name %!!! % end % ~ On client run #cat /var/tmp/test.txt Hi abc!!! Hi
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
Thanks Dylan. This approach looks good as and users don't have to add file resource explicitly. define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], ---*'another_resource' must be a variable as it is title of new_type resource. How can i pass title of new_type as parameter?* } new_type { 'another_resource': parameter1 = $file_path, } } I am confused where to place new defined type manifest file. The new_type (netdev_group) can be referred here: https://github.com/ganeshnalawade/puppet-netdev-stdlib-junos/tree/master/lib/puppet/type On Fri, Jun 19, 2015 at 7:30 AM, Dylan Ratcliffe dylan.ratcli...@puppetlabs.com wrote: That's close, You don't need to set ensure on a defined type unless you have exposed that as a paremeter, and you do need to set ensure for that file. Going back to the original issue of accessing the parameter of one resource from another, i'll give a little example of how I envision it: define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], } new_type { 'another_resource': parameter1 = $file_path, } } In this case the new_type resource can have access to a parameter in the file resource because it was passed in as a parameter and as a result is a variable that we can use. If we wanted to actually use this type we would do so like this: new_type::something { 'any_title': file_path = '/foo/bar.html', } Does this make sense? On Thursday, 18 June 2015 15:14:17 UTC+10, ganesh634 wrote: @Reid: Agreed it make sense to reference another resource instead of path string. The links you shared are very helpful. Thanks!!! @Dylan: While going through defined types i came across vhost here: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp I am not very clear how can i use it in my case. If a new defined type is used say new_type::load as below will it work? # /etc/puppetlabs/puppet/modules/new_type/manifests/load.pp define new_type::load ($path, $template_path){ include new_type file { $path: content = template($template_path), notify = new_type[ ? ], - *how to pass 'sample' here? * } } #/etc/puppetlabs/puppet/manifest/site.pp node 'node_name' { $names = [ abc, xyz ] new_type::load {'sample': path = '/var/tmp/test.txt' template_path = 'new_type/test_template.erb', ensure = present } } #/etc/puppetlabs/puppet/modules/new_type/templates/test_template.erb % @names.each do |name| % Hi %= name %!!! % end % ~ On client run #cat /var/tmp/test.txt Hi abc!!! Hi xyz!!! new_type resource 'sample' should be notified every time contents of test.txt is modified. On Thu, Jun 18, 2015 at 3:48 AM, Dylan Ratcliffe dylan.r...@puppetlabs.com wrote: Assuming that the file and the new_type resource will always be together I would wrap them in a defined type and expose everything you need as parameters. That way both can have access to it without any hacky stuff. I'm not sure of your level of Puppet knowledge so if that makes no sense let me know and I will explain. On Thursday, 18 June 2015 02:16:11 UTC+10, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
That's close, You don't need to set ensure on a defined type unless you have exposed that as a paremeter, and you do need to set ensure for that file. Going back to the original issue of accessing the parameter of one resource from another, i'll give a little example of how I envision it: define new_type::something ( $file_path, ) { file { $file_path: ensure = file, notify= New_type['another_resource'], } new_type { 'another_resource': parameter1 = $file_path, } } In this case the new_type resource can have access to a parameter in the file resource because it was passed in as a parameter and as a result is a variable that we can use. If we wanted to actually use this type we would do so like this: new_type::something { 'any_title': file_path = '/foo/bar.html', } Does this make sense? On Thursday, 18 June 2015 15:14:17 UTC+10, ganesh634 wrote: @Reid: Agreed it make sense to reference another resource instead of path string. The links you shared are very helpful. Thanks!!! @Dylan: While going through defined types i came across vhost here: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp I am not very clear how can i use it in my case. If a new defined type is used say new_type::load as below will it work? # /etc/puppetlabs/puppet/modules/new_type/manifests/load.pp define new_type::load ($path, $template_path){ include new_type file { $path: content = template($template_path), notify = new_type[ ? ], - *how to pass 'sample' here? * } } #/etc/puppetlabs/puppet/manifest/site.pp node 'node_name' { $names = [ abc, xyz ] new_type::load {'sample': path = '/var/tmp/test.txt' template_path = 'new_type/test_template.erb', ensure = present } } #/etc/puppetlabs/puppet/modules/new_type/templates/test_template.erb % @names.each do |name| % Hi %= name %!!! % end % ~ On client run #cat /var/tmp/test.txt Hi abc!!! Hi xyz!!! new_type resource 'sample' should be notified every time contents of test.txt is modified. On Thu, Jun 18, 2015 at 3:48 AM, Dylan Ratcliffe dylan.r...@puppetlabs.com javascript: wrote: Assuming that the file and the new_type resource will always be together I would wrap them in a defined type and expose everything you need as parameters. That way both can have access to it without any hacky stuff. I'm not sure of your level of Puppet knowledge so if that makes no sense let me know and I will explain. On Thursday, 18 June 2015 02:16:11 UTC+10, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value of both path need to be same all the time. -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- Michael Smith Sr. Software Engineer, Puppet Labs *PuppetConf 2015
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
Thanks Michael!!! new_type resource need to read content of 'interface' file and perform some action. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. Sorry i am new to Puppet resource development, I did not get above sentence. Can you please provide a example for it. new_type resource should take appropriate action only if contents of file 'interface' is changed or attribute values of new_type resource itself are changed between subsequent client run. To achieve this i am using notify relation. If user gives different path values in file and new_type resource the end result would not be as expected, hence to avoid such scenario's i want to remove 'path' from 'new_type' resource. On Wednesday, 17 June 2015 21:46:11 UTC+5:30, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com javascript: wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value of both path need to be same all the time. -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com javascript:. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- Michael Smith Sr. Software Engineer, Puppet Labs *PuppetConf 2015 http://2015.puppetconf.com/ is coming to Portland, Oregon! Join us October 5-9.* *Register now to take advantage of the Early Adopter discount https://www.eventbrite.com/e/puppetconf-2015-october-5-9-tickets-13115894995?discount=EarlyAdopter * *—**save $349!* -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/2efc42ab-eafc-4ffa-90ea-b1a27e538b64%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
What Michael said about the design is worth considering. If it makes sense to reference another resource instead of a path string (e.g. File[myfile]) and you're just curious about how to do it, there's code that does similar things in the puppetlabs/transition module, as well as in changes pending to the 2.x version of the puppetlabs/concat module https://forge.puppetlabs.com/puppetlabs/transition https://github.com/puppetlabs/puppetlabs-transition/blob/master/lib/puppet/provider/transition/ruby.rb and https://forge.puppetlabs.com/puppetlabs/concat https://github.com/hunner/puppetlabs-concat/blob/c34231d130591d60d122fdab8c2fe794a17666ef/lib/puppet/type/concat.rb#L222 If you mean to do this in Puppet code rather than in a type/provider, there are evaluation-order considerations that make it generally inadvisable. However, there is a function for that. https://forge.puppetlabs.com/puppetlabs/stdlib#getparam It just needs to be very, very carefully used to the point which in almost all cases it would be better to just use a variable instead. ~Reid -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/33462acb-e02a-4328-9030-a300a5ea5d51%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
Assuming that the file and the new_type resource will always be together I would wrap them in a defined type and expose everything you need as parameters. That way both can have access to it without any hacky stuff. I'm not sure of your level of Puppet knowledge so if that makes no sense let me know and I will explain. On Thursday, 18 June 2015 02:16:11 UTC+10, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com javascript: wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value of both path need to be same all the time. -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com javascript:. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- Michael Smith Sr. Software Engineer, Puppet Labs *PuppetConf 2015 http://2015.puppetconf.com/ is coming to Portland, Oregon! Join us October 5-9.* *Register now to take advantage of the Early Adopter discount https://www.eventbrite.com/e/puppetconf-2015-october-5-9-tickets-13115894995?discount=EarlyAdopter * *—**save $349!* -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/fb4e828e-0284-416d-8714-3b9314b47277%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
@Reid: Agreed it make sense to reference another resource instead of path string. The links you shared are very helpful. Thanks!!! @Dylan: While going through defined types i came across vhost here: https://github.com/puppetlabs/puppetlabs-apache/blob/master/manifests/vhost.pp I am not very clear how can i use it in my case. If a new defined type is used say new_type::load as below will it work? # /etc/puppetlabs/puppet/modules/new_type/manifests/load.pp define new_type::load ($path, $template_path){ include new_type file { $path: content = template($template_path), notify = new_type[ ? ], - *how to pass 'sample' here? * } } #/etc/puppetlabs/puppet/manifest/site.pp node 'node_name' { $names = [ abc, xyz ] new_type::load {'sample': path = '/var/tmp/test.txt' template_path = 'new_type/test_template.erb', ensure = present } } #/etc/puppetlabs/puppet/modules/new_type/templates/test_template.erb % @names.each do |name| % Hi %= name %!!! % end % ~ On client run #cat /var/tmp/test.txt Hi abc!!! Hi xyz!!! new_type resource 'sample' should be notified every time contents of test.txt is modified. On Thu, Jun 18, 2015 at 3:48 AM, Dylan Ratcliffe dylan.ratcli...@puppetlabs.com wrote: Assuming that the file and the new_type resource will always be together I would wrap them in a defined type and expose everything you need as parameters. That way both can have access to it without any hacky stuff. I'm not sure of your level of Puppet knowledge so if that makes no sense let me know and I will explain. On Thursday, 18 June 2015 02:16:11 UTC+10, Michael Smith wrote: There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 gane...@gmail.com wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value of both path need to be same all the time. -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- Michael Smith Sr. Software Engineer, Puppet Labs *PuppetConf 2015 http://2015.puppetconf.com/ is coming to Portland, Oregon! Join us October 5-9.* *Register now to take advantage of the Early Adopter discount https://www.eventbrite.com/e/puppetconf-2015-october-5-9-tickets-13115894995?discount=EarlyAdopter * *—**save $349!* -- You received this message because you are subscribed to a topic in the Google Groups Puppet Developers group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-dev/oBrN1RToyUI/unsubscribe. To unsubscribe from this group and all its topics, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/fb4e828e-0284-416d-8714-3b9314b47277%40googlegroups.com https://groups.google.com/d/msgid/puppet-dev/fb4e828e-0284-416d-8714-3b9314b47277%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- You received this message because
[Puppet-dev] Accessing attribute value of one resource in another resource impleataion
Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value of both path need to be same all the time. -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet-dev] Accessing attribute value of one resource in another resource impleataion
There's probably a way to do that, but I don't think it's a good idea. In order to look at the 'path' attribute of the 'file' resource, you'd need to specify which 'file' resource your new_type relates to. That means new_type would have a property with the value File['interface'], which isn't much different than having the 'path' property. Unless your type is specifically operating on the File resource abstraction, rather than the physical file itself, using 'path' seems to make more sense. Overloading the notify/require relationship to make that association would be a bad idea - they're 1-to-many and many-to-1 relationships - and probably complicated to make work. On Wed, Jun 17, 2015 at 7:38 AM, ganesh634 ganesh...@gmail.com wrote: Pasted below an example relation for new resource say 'new_type'. file { interface: path= /var/tmp/test.txt, content = template(module/test_template.erb), notify = new_type['sample'], } new_type { sample: path = /var/tmp/test.txt, active =true, ensure=present, } In 'new_type' resource implementation I want to access value of 'path' attribute value from 'file' resource to determine certain action in 'new_type' resource. With current approach I have to keep ‘path’ attribute in ‘new_type’ and mandate user to have ‘path’ value same as that of ‘path’ value in file resource. How can I access 'file’ resource 'path' attribute value in 'new_type' resource implementation? If it is possible I can remove the 'path' attribute from 'new_type' resource body as value of both path need to be same all the time. -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com https://groups.google.com/d/msgid/puppet-dev/004da5f1-be9f-4352-a1f8-b43f34c2d859%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- Michael Smith Sr. Software Engineer, Puppet Labs *PuppetConf 2015 http://2015.puppetconf.com/ is coming to Portland, Oregon! Join us October 5-9.* *Register now to take advantage of the Early Adopter discount https://www.eventbrite.com/e/puppetconf-2015-october-5-9-tickets-13115894995?discount=EarlyAdopter * *—**save $349!* -- You received this message because you are subscribed to the Google Groups Puppet Developers group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/CABy1mMJU9LmkYD7JjBsTVeTaXsaN4Sna7%2B9PSg5yuv2DNgg-XA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.