A puppet-lint plugin to check you are not using top scope fact variables like
$::operatingsystem
. You should use the $facts hash like
$facts['operatingsystem']
instead.
This linter will not covert from the legacy facts like
$facts['operatingsystem']
to $facts['os']['name']
. The legacy
facts linter can be
used to accomplish that.
In puppet 2.x facts were top scope variables and accessed as $operatingsystem
or $::operatingsystem
, the
latter being far more common
especially because the
linter enforces that convention.
Puppet 3.5 added a $facts
hash to access facts like
$facts['operatingsystem']
. This works if you set trusted_node_data = true
but it was
not enabled by default. Puppet
4 has it enabled by default.
This puppet-lint plugin will help find facts referenced as top scope variables
and replace them with the $facts
hash to improve readability of code. Its only
useful if you're running puppet 3.5 to 3.8 with trusted_node_data enabled, or if
you're running puppet 4.
$::operatingsystem
but not $operatingsystem
.$ gem install puppet-lint-top_scope_facts-check
gem 'puppet-lint-top_scope_facts-check', :require => false
$service_name = $::operatingsystem {
'CentOS' => 'httpd',
'Debian' => 'apache2',
}
$service_name = $facts['operatingsystem'] {
'CentOS' => 'httpd',
'Debian' => 'apache2',
}
You can whitelist top scope variables to ignore via the Rake task. You should
insert the following line to your Rakefile
.
PuppetLint.configuration.top_scope_variables = ['location', 'role']
To disable this check, you can add --no-top_scope_facts
to your puppet-lint
command line.
$ puppet-lint --no-top_scope_facts path/to/file.pp
Alternatively, if you’re calling puppet-lint via the Rake task, you should
insert the following line to your Rakefile
.
PuppetLint.configuration.send('disable_top_scope_facts')
Alternatively, you can disable it directly in your puppet manifest.
# lint:ignore:top_scope_facts
$service_name = $::operatingsystem {
'CentOS' => 'httpd',
'Debian' => 'apache2',
}
# lint:endignore
Copyright 2016 Mark McKinstry
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.