0

I got following error while running below puppet module. I have 2 agents one is ubuntu 18.04 and centos7 Below code works in ubuntu and stopping the firewall, but in centos i got below error.

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: {"message":"Server Error: Evaluation Error: A substring operation does not accept a String as a character index. Expected an Integer (file: /etc/puppetlabs/code/modules/service_disable_firewall/manifests/init.pp, line: 9, column: 21) on node node-01.home86.com","issue_kind":"RUNTIME_ERROR"} Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run

Line 9 is

case $facts['os']['family'] {

My code is

class service_disable_firewall {

  case $facts['os']['family'] {
    'Debian': {
      service { 'ufw':
      ensure => stopped,
      }
    }
    'RedHat': {
      service { 'firewalld':
      ensure => stopped,
      }
    }
  }
}

Thanks in advance

  • Issue got resolved after changing "case" as below case $::operatingsystem { – madprinciple Mar 02 '19 at 11:50
  • This sounds like `$facts['os']` is resolving to a String instead of a Hash on your Centos7 system, which means either there is a bug in Facter or a problem on that system with what the Facter provider is using. – Matthew Schuchard Mar 02 '19 at 13:59
  • Thank you for the explanation – madprinciple Mar 02 '19 at 18:11
  • ... or if you're using version 3 of the Puppet agent, it could just be that fact stringification is enabled on the RedHat machine, but not on the Ubuntu machine. This was configuration setting `stringify_facts`, and it defaulted to `true`. It was removed in Puppet 4: in that and subsequent versions, facts are never stringified. – John Bollinger Mar 04 '19 at 15:01
  • Hey !! you are correct, in centos it was puppet 3, i updated it to 5 and now it works can you post this as a answer :) – madprinciple Mar 04 '19 at 18:25

2 Answers2

1

Issue got resolved after changing "case" as below

case $::operatingsystem {

But still not sure why did my first code fail.

0

Try ${facts['os']['family']} instead of $facts['os']['family']

Works for me on both

RASG
  • 5,988
  • 4
  • 26
  • 47