rodjek / puppet-lint

Check that your Puppet manifests conform to the style guide
MIT License
820 stars 204 forks source link

NoMethodError: undefined method `end_with?' for nil:NilClass #704

Closed TinajaLabs closed 7 years ago

TinajaLabs commented 7 years ago

running on mac

Whoops! It looks like puppet-lint has encountered an error that it doesn't know how to handle.

puppet-lint version: 2.2.1 ruby version: 2.0.0-p648 platform: universal.x86_64-darwin15 file path: manifests//mon_icinga2.pp file contents:

# myxmon_server::mon_icinga2
# ===========================
#

class myxmon_server::mon_icinga2() {

    $ido_db_name = hiera('ido_db_name', 'my_db_name')
    $ido_db_user = hiera('ido_db_user', 'my_db_user')
    $ido_db_pass = hiera('ido_db_pass', 'my_db_pass')
    $ticket_salt = hiera('ticket_salt', 'fd77b14ebd41')
    $master_fqdn = hiera('master_fqdn', 'mon.mysys.myx')
    $master_ip = hiera('master_ip', '192.168.140.14')

    $this_domain    = $::facts['networking']['domain']
    $track_name     = $::facts['country']
    $fqdn           = $::facts['networking']['fqdn']
    $hostname       = $::facts['networking']['hostname']
    $hostip         = $::facts['networking']['ip']

    # as of 2017.04.19, we only deal with master/client, no satellite level
    if 'mon' in $hostname {
        notify { '==============================>   This is being configured as a MASTER node': }
        $feat_list  = ['checker','mainlog','notification','statusdata','compatlog','command']
    }
    else {
        notify { '==============================>   This is being configured as a CLIENT node': }
        $feat_list  = ['checker','mainlog']
    }

    # for MASTER - all master nodes need to have hostname = 'mon'
    if 'mon' in $hostname {

        class { '::mysql::server':
            create_root_user => true,
            root_password       => 'yadayada',
            create_root_my_cnf  => true,
            install_secret_file => '/root/.mysql_secret',
            package_name        => 'mysql-community-server',
            package_ensure      => '5.7.17',
        }

        # ::mysql::db { $ido_db_name:
        #     user     => $ido_db_user,
        #     password => $ido_db_pass,
        #     host     => 'localhost',
        #     grant    => ['ALL'],
        # }

        class { '::icinga2':
            manage_package => true,
            confd          => false,
            features       => ['checker','mainlog','notification','statusdata','compatlog','command'],
            constants      => {
                'ZoneName'         => 'zone_master',
                'NodeName'         => "${::fqdn}",
                'PluginDir'        => '/etc/icinga2/libexec',
                'CustomPluginDir'  => '/myx/icinga/plugins',
                'PluginContirbDir' => '/usr/local/nagios/plugins',
                'TrackName'        => "${track_name}",
                'SourceName'       => 'mon.xxx.myx',
                'TicketSalt'       => $ticket_salt,
                'baseWikiURL'      => 'http://localhost/my/index.php/',
                'baseSnmpWalk'     => 'snmpwalk -v 2c -c public ',
                'monlevel'         => '2',
            },
        }

        class { '::icinga2::feature::idomysql':
            # this configuration uses some code that fails certain conditions on ruby 1.8.7 :(
            # must be run before  icinga2::object::zone (see below)
            user          => $ido_db_user,
            password      => $ido_db_pass,
            database      => $ido_db_name,
            import_schema => true,
            require       => Mysql::Db[$ido_db_name],
        }

        class { '::icinga2::feature::api':
            accept_commands => true,
            accept_config   => false,
            endpoints       => {
            'NodeName'       => {},
            'db01.mysys.myx' => {
                'host'  => '192.168.140.28',
            },
            'ui.mysys.myx'   => {
                'host'  => '192.168.140.23',
            },
            },
            zones           => {
            'zone_master' => {
                'endpoints' => ["${master_fqdn}"],
            },
            "zone_${track_name}" => {
                'endpoints' => ['db.mysys.myx','ui.mysys.myx'],
                'parent'    => 'master',
            },
            },
        }

        # all hosts get this
        # icinga2::object::zone { 'global-templates':
        #     global => true,
        # }
        # creates this in the zones.conf file:
        # object Zone "global-templates"  {
        #     global = true
        # }

        }
        else {

        # for all CLIENTS

        class { '::icinga2':
            manage_package => true,
            confd          => false,
            features       => ['checker','mainlog'],
            constants      => {
                'NodeName'         => "${::fqdn}",
                'PluginDir'        => '/etc/icinga2/libexec',
                'CustomPluginDir'  => '/myx/icinga/plugins',
                'PluginContirbDir' => '/usr/local/nagios/plugins',
                'TrackName'        => "${track_name}",
                'SourceName'       => 'mon.xxx.xxx',
                'TicketSalt'       => "${ticket_salt]",
                'baseWikiURL'      => 'http://10.0.1.12/tw/index.php/',
                'baseSnmpWalk'     => 'snmpwalk -v 2c -c public ',
                'monlevel'         => '2',
            },
        }

        # build the endpoints and zones for clients
        class { '::icinga2::feature::api':
          pki             => 'none',
          accept_commands => true,
          accept_config   => true,
          endpoints       => {
            'NodeName'    => {},
            "$master_fqdn" => {
              'host' => "$master_ip",
            }
          },
          zones           => {
            'ZoneName' => {
              'endpoints' => ['NodeName'],
              'parent'    => 'zone_master',
            },
            'zone_master'      => {
              'endpoints' => ["$master_fqdn"],
            },
          },
        }

    }

    # install graphite feature only on mon master
    if 'mon' in $hostname {
        # configure graphite metrics output
        class { '::icinga2::feature::graphite':
            host                    => hiera('graphite_host',  'mon.soc.myx'),
            port                    => hiera('graphite_port',  '2003'),
            enable_send_thresholds  => true,
            enable_send_metadata    => true,
            host_name_template      => 'myx.$host.name$.host.$host.check_command$',
            service_name_template   => 'myx.$host.name$.services.$service.name$.$service.check_command$',
        }
    }

    # create a parallel /etc/icings2/ dir with default configs
    file {'/etc/icinga2-myx':
        ensure  => directory,
        recurse => true,
        purge   => true,
        sourceselect => all,
        # the ending slash is critical in the next line...  ???
        source  => 'puppet:///modules/myxmon_server/icinga2-myx/',
    }
}

error:

NoMethodError: undefined method `end_with?' for nil:NilClass
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/lexer.rb:297:in `slurp_string'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/lexer.rb:206:in `tokenise'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/lexer.rb:447:in `interpolate_string'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/lexer.rb:208:in `tokenise'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/checks.rb:25:in `load_data'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/checks.rb:53:in `run'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint.rb:191:in `run'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/bin.rb:59:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/bin.rb:56:in `each'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/lib/puppet-lint/bin.rb:56:in `run'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.2.1/bin/puppet-lint:7:in `<top (required)>'
/usr/local/bin/puppet-lint:23:in `load'
/usr/local/bin/puppet-lint:23:in `<main>'
rnelson0 commented 7 years ago

puppet-lint is meant to run after the file is validated. The 3.0.0 train will properly alert on this. Until then, you must verify this yourself first. Here's the error I received validating it:

Error: Could not parse for environment production: Unclosed quote after '' followed by '',\n  ...' at /home/rn7284/puppet/controlrepo/test.pp:171:104

The issue is actually on line 130, mismatched bracket types: 'TicketSalt' => "${ticket_salt]",

TinajaLabs commented 7 years ago

OK... feeling lame now. That didn't stand out in Sublime...

Thanks for the assistance.