[Puppet Users] Can't access custom fact as hash
I defined this custom fact, which queries a local tool to determine what roles a particular system should have assigned to it: Facter.add(:dgroles) do setcode do roles = {} res_hash = {} results = Facter::Core::Execution.exec("dg-role -b").split("/n") results.each do |res| rs=res.split(" ") res_hash[rs[0]] = rs[1].split(',') end res_hash end end This works fine from the command line: $ facter -p dgroles {"BAD"=>["wks", "lnx"]} And when I use it in a notify: ---manifest excerpt--- notify { "roles: $::dgroles": } which produces: Notice: roles: {"BAD"=>["wks", "lnx"]} But when I try to actually use the hash, as in: ---manifest excerpt--- if count(delete(keys($::dgroles),'GOOD')) > 0 { exec { 'dg-role-a-update': command => 'dg-role -a update', } } Then I get this error when running puppet agent -t: Error: Could not retrieve catalog from remote server: Error 400 on SERVER: keys(): Requires hash to work with at /etc/puppet/environments/roles/modules/dglib/manifests/config.pp:54 on node zw129.damascusgrp.com What am I doing wrong here? -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/a41759da-de77-408e-ba22-6b12bc0d356e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Puppet Users] Re: Can't access custom fact as hash
This is on Puppet open source V3.8.3 server and V3.8.1 client. On Wednesday, November 4, 2015 at 8:08:20 AM UTC-5, Bret Wortman wrote: > > I defined this custom fact, which queries a local tool to determine what > roles a particular system should have assigned to it: > > Facter.add(:dgroles) do > setcode do > roles = {} > res_hash = {} > results = Facter::Core::Execution.exec("dg-role -b").split("/n") > results.each do |res| > rs=res.split(" ") > res_hash[rs[0]] = rs[1].split(',') > end > res_hash > end > end > > > This works fine from the command line: > > $ facter -p dgroles > {"BAD"=>["wks", "lnx"]} > > > And when I use it in a notify: > > ---manifest excerpt--- > > notify { "roles: $::dgroles": } > > > which produces: > > Notice: roles: {"BAD"=>["wks", "lnx"]} > > > But when I try to actually use the hash, as in: > > ---manifest excerpt--- > > if count(delete(keys($::dgroles),'GOOD')) > 0 { > exec { 'dg-role-a-update': > command => 'dg-role -a update', > } > } > > > Then I get this error when running puppet agent -t: > > Error: Could not retrieve catalog from remote server: Error 400 on SERVER: > keys(): Requires hash to work with at > /etc/puppet/environments/roles/modules/dglib/manifests/config.pp:54 on node > zw129.damascusgrp.com > > > What am I doing wrong here? > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/edbd7141-97a7-47a3-84a4-4cb2c45b4109%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Puppet Users] epp conditionals not working, erb is
As epp is the way to go, I'm trying to create all my new templates in epp-format. I have a problem with using conditionals, though. I have the following conditional in an epp template: ... <%- if $xxx_yyy == true { -%> // code here <%- } -%> ... When I apply this template with a defined type resource that sets: ... xxx_yyy => true, ... Nothing happens on that node. Just to test what the value is of $xxx_yyy, I added "Value variable: <%= $xxx_yyy %>" to the templat, but that stays empty. I call the epp-template with: content => epp('module/template.epp'), If I copy the template to template.erb and modify the code as needed: ... <%- if @sug_saml_enable -%> // code here <%- end -%> ... All is working well when calling the template with: content => template('module/template.erb'), What am I doing wrong? Can someone point me in the right direction? This is with puppet-agent 4.2.3 and the newest puppetserver. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/cc95567f-f19b-460c-994f-14426214874c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Puppet Users] Re: epp conditionals not working, erb is
I ran into this problem also. Are you access the variable $xxx_yyy will full puppet path? IE $classname::xxx_yyy If not you need to pass the variable into the template like this. content => epp('module/template.epp', { 'xxx_yyy' => "$xxx_yyy"}), Hope This helps On Wednesday, November 4, 2015 at 8:24:59 AM UTC-5, Erwin Bogaard wrote: > > As epp is the way to go, I'm trying to create all my new templates in > epp-format. > I have a problem with using conditionals, though. > > I have the following conditional in an epp template: > ... > <%- if $xxx_yyy == true { -%> > // code here > <%- } -%> > ... > > When I apply this template with a defined type resource that sets: > ... > xxx_yyy => true, > ... > > Nothing happens on that node. > Just to test what the value is of $xxx_yyy, I added "Value variable: <%= > $xxx_yyy %>" to the templat, but that stays empty. > > I call the epp-template with: > > content => epp('module/template.epp'), > > > If I copy the template to template.erb and modify the code as needed: > ... > <%- if @sug_saml_enable -%> > // code here > <%- end -%> > ... > > All is working well when calling the template with: > > content => template('module/template.erb'), > > > What am I doing wrong? > Can someone point me in the right direction? > > This is with puppet-agent 4.2.3 and the newest puppetserver. > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/c1c6ee87-9fb9-47e6-a7ba-e2be492b450b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Puppet Users] Re: epp conditionals not working, erb is
Aaron, thanks! That was the problem. I think I misread (or didn't read) the paragraph "Accessing variables" in the documentation. Thanks for helping me out with this. On Wednesday, 4 November 2015 14:34:11 UTC+1, Aaron Russell wrote: > > I ran into this problem also. > > Are you access the variable $xxx_yyy will full puppet path? IE > $classname::xxx_yyy > > If not you need to pass the variable into the template like this. > > content => epp('module/template.epp', { 'xxx_yyy' => "$xxx_yyy"}), > > Hope This helps > > > On Wednesday, November 4, 2015 at 8:24:59 AM UTC-5, Erwin Bogaard wrote: >> >> As epp is the way to go, I'm trying to create all my new templates in >> epp-format. >> I have a problem with using conditionals, though. >> >> I have the following conditional in an epp template: >> ... >> <%- if $xxx_yyy == true { -%> >> // code here >> <%- } -%> >> ... >> >> When I apply this template with a defined type resource that sets: >> ... >> xxx_yyy => true, >> ... >> >> Nothing happens on that node. >> Just to test what the value is of $xxx_yyy, I added "Value variable: <%= >> $xxx_yyy %>" to the templat, but that stays empty. >> >> I call the epp-template with: >> >> content => epp('module/template.epp'), >> >> >> If I copy the template to template.erb and modify the code as needed: >> ... >> <%- if @sug_saml_enable -%> >> // code here >> <%- end -%> >> ... >> >> All is working well when calling the template with: >> >> content => template('module/template.erb'), >> >> >> What am I doing wrong? >> Can someone point me in the right direction? >> >> This is with puppet-agent 4.2.3 and the newest puppetserver. >> > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/81bdcddd-95f9-4cd0-9d2d-00bfb30b35f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[Puppet Users] Re: Can't access custom fact as hash
For completeness' sake, the answer was to set stringify_facts = false in puppet.conf's [main] section. On Wednesday, November 4, 2015 at 8:09:36 AM UTC-5, Bret Wortman wrote: > > This is on Puppet open source V3.8.3 server and V3.8.1 client. > > On Wednesday, November 4, 2015 at 8:08:20 AM UTC-5, Bret Wortman wrote: >> >> I defined this custom fact, which queries a local tool to determine what >> roles a particular system should have assigned to it: >> >> Facter.add(:dgroles) do >> setcode do >> roles = {} >> res_hash = {} >> results = Facter::Core::Execution.exec("dg-role -b").split("/n") >> results.each do |res| >> rs=res.split(" ") >> res_hash[rs[0]] = rs[1].split(',') >> end >> res_hash >> end >> end >> >> >> This works fine from the command line: >> >> $ facter -p dgroles >> {"BAD"=>["wks", "lnx"]} >> >> >> And when I use it in a notify: >> >> ---manifest excerpt--- >> >> notify { "roles: $::dgroles": } >> >> >> which produces: >> >> Notice: roles: {"BAD"=>["wks", "lnx"]} >> >> >> But when I try to actually use the hash, as in: >> >> ---manifest excerpt--- >> >> if count(delete(keys($::dgroles),'GOOD')) > 0 { >> exec { 'dg-role-a-update': >> command => 'dg-role -a update', >> } >> } >> >> >> Then I get this error when running puppet agent -t: >> >> Error: Could not retrieve catalog from remote server: Error 400 on >> SERVER: keys(): Requires hash to work with at >> /etc/puppet/environments/roles/modules/dglib/manifests/config.pp:54 on node >> zw129.damascusgrp.com >> >> >> What am I doing wrong here? >> > -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/7b2f36a8-3709-4442-b17a-aabaff678c69%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] Re: Forge ACL Module 1.1.1 on Windows 7 x64 SP1
On Mon, Oct 19, 2015 at 10:10 AM, jmp242 wrote: > Hmm, so on one test computer, the upgrade to puppet 3.8.3 fixed the issue. > On the second test computer, it didn't - everything remains the same, but > getting the same repeated ACE... > What does 'cacls *folderlocation*' return? > > > On Thursday, October 15, 2015 at 12:27:34 AM UTC-4, Rob Reynolds wrote: >> >> >> >> On Thu, Oct 1, 2015 at 8:09 AM, jmp242 wrote: >> >> Puppet 3.8.1 on Windows currently. puppet module list doesn't return >> anything for me. I'm downloading the zip file and unzipping the module into >> a folder. I then copy the folder into my local dev modules directory using >> Geppeto, and doing the same for any dependencies. I then check into our SVN >> the modules, and tag them with the version they are from forge if public, >> or an internal version for our custom modules. I then check out the tag or >> svn switch to the latest tag on the puppet server dev module directory. >> >> >> Ah okay. I'm wondering what might cause issues surrounding 3.8.1 and ACL >> provider. An ACE with the same structure 142 times though, I'm wondering if >> there is a memory issue there. >> >> >> >> On Wednesday, September 30, 2015 at 3:38:49 PM UTC-4, Rob Reynolds wrote: >> >> Thanks. I'm surprised that a 'puppet agent --trace --debug --verbose' >> didn't turn up any more information about the error. >> >> Can you remind me again what version of Puppet you have installed? >> >> And the modules, `puppet module list`. How are you installing these >> modules by the way? >> >> On Tue, Sep 29, 2015 at 2:43 PM, jmp242 wrote: >> >> Sure, that's perhaps misleading a little - our internal custom puppet >> module is called yum as it was created for EL6 first. When we got a package >> manager on Windows, i.e. chocolatey, it seemed to make sense to put it in >> the Windows section of the yum module. By that I mean we have a switch on >> kernel in our modules. Here's the complete module: >> class yum ($choco_repo_url, $choco_repo_name) { >> schedule { 'monday_updates': >> range => '22:00 - 12:00', >> weekday => 'Monday', >> } >> >> schedule { 'tuesday_updates': >> range => '10:00 - 12:00', >> weekday => 'Tuesday', >> } >> >> schedule { 'daily_updates': >> period => daily, >> range => '22:00-3:00', >> } >> >> define repo { >> file { "${title}": >> path => "/etc/yum.repos.d/${title}", >> source => "puppet:///modules/${caller_module_name}/${title}", >> ensure => 'present', >> owner => root, >> group => root, >> mode => "644", >> notify => Exec["yum-clean-all"], >> } >> >> } >> >> case $kernel { >> 'linux' : { >> package { 'yum': ensure => present, } >> >> package { 'yum-autoupdate': ensure => present, } >> >> repo { "sl-classe.repo": } >> >> file { "sl-classe-testing": >> content => template('yum/sl-classe-testing.repo.erb'), >> path=> "/etc/yum.repos.d/sl-classe-testing.repo", >> owner => root, >> group => root, >> mode=> 644, >> ensure => present, >> notify => Exec["yum-clean-all"], >> } >> >> file { "yum.conf": >> source => "puppet:///modules/yum/yum.conf", >> path => "/etc/yum.conf", >> owner => root, >> group => root, >> mode => 644, >> ensure => present, >> } >> >> file { "sl-lepp": >> path => "/etc/yum.repos.d/sl-lepp.repo", >> ensure => absent, >> } >> >> file { "sl-lepp-testing": >> path => "/etc/yum.repos.d/sl-lepp-testing.repo", >> ensure => absent, >> } >> >> exec { "yum-clean-all": >> command => "yum clean all", >> refreshonly => true, >> } >> >> case $operatingsystemmajrelease { >> '6' : { >> $sl6repos = ["devtoolset.repo", "sl-other.repo", "sl.repo"] >> >> repo { $sl6repos: } >> >> file { "softwarecollections": >> source => >> "puppet:///modules/yum/sl6-softwarecollections.repo", >> path => "/etc/yum.repos.d/softwarecollections.repo", >> owner => root, >> group => root, >> mode => 644, >> ensure => present, >> notify => Exec["yum-clean-all"], >> } >> >> exec { "yum-autoupdate": >> command => "mv /etc/cron.daily/yum-autoupdate >> /etc/cron.weekly/yum-autoupdate", >> onlyif => "[ -f /etc/cron.daily/yum-autoupdate ]", >> } >> >> file { "/etc/cron.daily/yum-autoupdate": ensure => absent, } >> >> file { "/etc/cron.weekly/yum-autoupdate": ensure => present, } >> Exec['yum-autoupdate'] -> File['/etc/cron.daily/yum-autoupdate' >> ] -> File['/etc/cron.weekly/yum-autoupdate'] >> >> } >> '7' : { >> packages::removepackage { "yum-conf-sl7x": } >> >> $sl7
Re: [Puppet Users] powershell detect then install nonexistent or replace existing custom service
Thanks Rob! This appears to work well after looking into your suggestions...I tried to include an "unless" statement at the end of the Install New FooService Service" block for a little extra security, but it didn't seem to like that so I removed it - I'm not sure of the reason for that, however. The refreshonly is there to make sure this doesn't just randomly uninstall and install the service but only does it when new code has been dropped into place or a file has been altered against policy and the service may be corrupted. class FooService::install { if $::osfamily == 'windows' { File { source_permissions => ignore } } file { 'C:\\Services\\Win\\FooServiceConsumerSvc\\': ensure => present, source => 'puppet:///modules/FooService/FooService', recurse => true, purge => true, force => true, } exec { 'Uninstall Old FooService Service': command => 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /Logfile= /InstallStateDir="C:\Services\Logs\Win" /uninstall "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', provider=> powershell, subscribe => File['C:\\Services\\Win\\FooServiceConsumerSvc\\'], onlyif => 'if ((Get-Service -name "FooService") -ne $null)', refreshonly => true, notify => Exec['Install New FooService Service'], } exec { 'Install New FooService Service': command => 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /username=AD\user /password=password /Logfile= /InstallStateDir="C:\Services\Logs\Win" "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', provider=> powershell, refreshonly => true, } } On Tuesday, November 3, 2015 at 10:44:03 AM UTC-5, Rob Reynolds wrote: > > > > On Fri, Oct 30, 2015 at 8:50 AM, Aaron > > wrote: > >> I have a question and hopefully someone can help me resolve it - >> >> In windows, I have custom services that I need to manage. I've been >> running this code for a while, and it works well for several custom Windows >> services, but the problem is I cannot run it on a bare server without >> manual intervention (i.e. manually running the installer powershell script >> to create the Service before puppet will complete successfully after >> that). It will fail because the Detect does not see the service, so the >> Uninstall cannot succeed. I am trying to figure out how to use an ELSE off >> of the Detect Exec block, but am not sure how to make that work. And I am >> unsure if there is anything clever I can do with the NOTIFY in the detect >> block. >> >> Can anyone offer some assistance? >> >> FYI I do not have installers, I have the bare files that are moved into >> place in the first File block, and then the Detect runs if any changes are >> made to any files in the service. Hopefully that remains clear in my >> attempt to make this generic. >> >> class FooService::install { >> >> if $::osfamily == 'windows' { >> File { source_permissions => ignore } >> } >> >> file { 'C:\\Services\\Win\\FooServiceConsumerSvc\\': >> ensure => present, >> source => 'puppet:///modules/FooService/FooService', >> recurse => true, >> purge => true, >> force => true, >> } >> >> exec { 'Detect FooService Service': >> command => 'if ((Get-Service -name "FooService") -ne $null)', >> > > You could add more to the command to run here. > > > >> provider=> powershell, >> subscribe => File['C:\\Services\\Win\\FooServiceConsumerSvc\\'], >> refreshonly => true, >> notify => Exec['Uninstall Old FooService Service'], >> returns => 0, >> } >> >> exec { 'Uninstall Old FooService Service': >> command => >> 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /Logfile= >> /InstallStateDir="C:\Services\Logs\Win" /uninstall >> "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', >> provider=> powershell, >> refreshonly => true, >> notify => Exec['Install New FooService Service'], >> } >> >> exec { 'Install New FooService Service': >> command => >> 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe >> /username=AD\user /password=password /Logfile= >> /InstallStateDir="C:\Services\Logs\Win" >> "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', >> provider=> powershell, >> refreshonly => true, >> } >> > > I would move this from a refresh only and introduce onlyif or unless where > you check to see if the service is installed. And if it is not, then > install it. For an example of unless see > > > https://github.com/chocolatey/puppet-chocolatey/blob/3cce9e59d01f774ac48c40ec452b04eee9a81ebb/manifests/config.pp#L20-L25 > > > >> >> } >> >> >> -- >> 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-u
Re: [Puppet Users] powershell detect then install nonexistent or replace existing custom service
blech - nevermind. still throws horrible errors when the service has not been installed yet and puppet runs (such as on a new VM). Is there any way to have it see that there is an error during the uninstall and then run an ELSE and move onto the Install portion without getting hung up on not being able to uninstall first? this is the step I can't seem to figure out. Aaron On Wednesday, November 4, 2015 at 2:58:46 PM UTC-5, Aaron wrote: > > Thanks Rob! > > This appears to work well after looking into your suggestions...I tried to > include an "unless" statement at the end of the Install New FooService > Service" block for a little extra security, but it didn't seem to like that > so I removed it - I'm not sure of the reason for that, however. > The refreshonly is there to make sure this doesn't just randomly uninstall > and install the service but only does it when new code has been dropped > into place or a file has been altered against policy and the service may be > corrupted. > > class FooService::install { > > > if $::osfamily == 'windows' { > File { source_permissions => ignore } > } > > > file { 'C:\\Services\\Win\\FooServiceConsumerSvc\\': > ensure => present, > source => 'puppet:///modules/FooService/FooService', > recurse => true, > purge => true, > force => true, > } > > > exec { 'Uninstall Old FooService Service': > command => > 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe > /Logfile= /InstallStateDir="C:\Services\Logs\Win" /uninstall > "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', > provider=> powershell, > subscribe => File['C:\\Services\\Win\\FooServiceConsumerSvc\\'], > onlyif => 'if ((Get-Service -name "FooService") -ne $null)', > refreshonly => true, > notify => Exec['Install New FooService Service'], > } > > > exec { 'Install New FooService Service': > command => > 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe > /username=AD\user /password=password /Logfile= > /InstallStateDir="C:\Services\Logs\Win" > "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', > provider=> powershell, > refreshonly => true, > } > > > } > > > On Tuesday, November 3, 2015 at 10:44:03 AM UTC-5, Rob Reynolds wrote: >> >> >> >> On Fri, Oct 30, 2015 at 8:50 AM, Aaron wrote: >> >>> I have a question and hopefully someone can help me resolve it - >>> >>> In windows, I have custom services that I need to manage. I've been >>> running this code for a while, and it works well for several custom Windows >>> services, but the problem is I cannot run it on a bare server without >>> manual intervention (i.e. manually running the installer powershell script >>> to create the Service before puppet will complete successfully after >>> that). It will fail because the Detect does not see the service, so the >>> Uninstall cannot succeed. I am trying to figure out how to use an ELSE off >>> of the Detect Exec block, but am not sure how to make that work. And I am >>> unsure if there is anything clever I can do with the NOTIFY in the detect >>> block. >>> >>> Can anyone offer some assistance? >>> >>> FYI I do not have installers, I have the bare files that are moved into >>> place in the first File block, and then the Detect runs if any changes are >>> made to any files in the service. Hopefully that remains clear in my >>> attempt to make this generic. >>> >>> class FooService::install { >>> >>> if $::osfamily == 'windows' { >>> File { source_permissions => ignore } >>> } >>> >>> file { 'C:\\Services\\Win\\FooServiceConsumerSvc\\': >>> ensure => present, >>> source => 'puppet:///modules/FooService/FooService', >>> recurse => true, >>> purge => true, >>> force => true, >>> } >>> >>> exec { 'Detect FooService Service': >>> command => 'if ((Get-Service -name "FooService") -ne $null)', >>> >> >> You could add more to the command to run here. >> >> >> >>> provider=> powershell, >>> subscribe => File['C:\\Services\\Win\\FooServiceConsumerSvc\\'], >>> refreshonly => true, >>> notify => Exec['Uninstall Old FooService Service'], >>> returns => 0, >>> } >>> >>> exec { 'Uninstall Old FooService Service': >>> command => >>> 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /Logfile= >>> /InstallStateDir="C:\Services\Logs\Win" /uninstall >>> "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', >>> provider=> powershell, >>> refreshonly => true, >>> notify => Exec['Install New FooService Service'], >>> } >>> >>> exec { 'Install New FooService Service': >>> command => >>> 'C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe >>> /username=AD\user /password=password /Logfile= >>> /InstallStateDir="C:\Services\Logs\Win" >>> "C:\Services\Win\FooServiceConsumerSvc\FooService.exe"', >>>