Git Product home page Git Product logo

puppet-lint-legacy_facts-check's Introduction

Build Status Gem Total Downloads Latest Downloads

Overview

Puppet 3.5 optionally added structured facts as well as the global facts hash. They were both turned on by default in puppet 4.

This linter will convert from legacy facts like $::operatingsystem or legacy hashed facts like $facts['operatingsystem'] to the new structured facts like $facts['os']['name'].

If you only want to convert from facts like $::operatingsystem to the facts hash like $facts['operatingsystem'], you want the top scope facts linter.

Installing

From the command line

$ gem install puppet-lint-legacy_facts-check

In a Gemfile

gem 'puppet-lint-legacy_facts-check', :require => false

Checks

What you have done

$package_name = $::operatingsystem {
  'CentOS' => 'httpd',
  'Debian' => 'apache2',
}
$package_name = $facts['operatingsystem'] {
  'CentOS' => 'httpd',
  'Debian' => 'apache2',
}

What you should have done

$package_name = $facts['os']['name'] {
  'CentOS' => 'httpd',
  'Debian' => 'apache2',
}

Disabling the check

To disable this check, you can add --no-legacy_facts to your puppet-lint command line.

$ puppet-lint --no-legacy_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_legacy_facts')

Alternatively, you can disable it directly in your puppet manifest.

# lint:ignore:legacy_facts
$package_name = $facts['operatingsystem'] {
  'CentOS' => 'httpd',
  'Debian' => 'apache2',
}
# lint:endignore

Limitations

The linter will only find and work on top scope facts like $::osfamily, non-top scope facts like $osfamily will not be found or fixed.

Some facts have no equivalent in the structured fact list:

memoryfree_mb

There is no fact that returns exclusively in MiB.

The closest equivalent is $facts['memory']['system'][available'] or $facts['memory']['system']['available_bytes'].

See facter documentation on memory.

memorysize_mb

There is no fact that returns exclusively in MiB.

The closest equivalent is $facts['memory']['system']['total'] or $facts['memory']['system']['total_bytes'].

See facter documentation on memory.

swapfree_mb

There is no fact that returns exclusively in MiB.

The closest equivalent is $facts['memory']['swap']['available'] or $facts['memory']['swap']['available_bytes'].

See facter documentation on memory.

swapsize_mb

There is no fact that returns exclusively in MiB.

The closest equivalent is $facts['memory']['swap']['used'] or $facts['memory']['swap']['used_bytes'].

See facter documentation on memory.

blockdevices

This returns a string containing all block devices separated by a comma.

This can be duplicated using puppetlabs/stdlib and the following: join(keys($facts['disks']), ',')

interfaces

This returns a string containing all interfaces separated by a comma.

This can be duplicated using puppetlabs/stdlib and the following: join(keys($facts['networking']['interfaces']), ',').

zones

This returns a string containing all zone names separated by a comma.

This can be duplicated using puppetlabs/stdlib and the following: join(keys($facts['solaris_zones']['zones']), ',')

sshfp_dsa

This returns a string containing both the SHA1 and SHA256 fingerprint for the DSA algorithm.

This can be duplicated using the following string: "$facts['ssh']['dsa']['fingerprints']['sha1'] $facts['ssh']['dsa']['fingerprints']['sha256']"

sshfp_ecdsa

This returns a string containing both the SHA1 and SHA256 fingerprint for the ECDSA algorithm.

This can be duplicated using the following string: "$facts['ssh']['ecdsa']['fingerprints']['sha1'] $facts['ssh']['ecdsa']['fingerprints']['sha256']"

sshfp_ed25519

This returns a string containing both the SHA1 and SHA256 fingerprint for the Ed25519 algorithm.

This can be duplicated using the following string: "$facts['ssh']['ed25519']['fingerprints']['sha1'] $facts['ssh']['ed25519']['fingerprints']['sha256']"

sshfp_rsa

This returns a string containing both the SHA1 and SHA256 fingerprint for the RSA algorithm.

This can be duplicated using the following string: "$facts['ssh']['rsa']['fingerprints']['sha1'] $facts['ssh']['rsa']['fingerprints']['sha256']"

License

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.

puppet-lint-legacy_facts-check's People

Contributors

bart2 avatar baurmatt avatar mmckinst avatar rodjek avatar seanmil avatar traylenator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

puppet-lint-legacy_facts-check's Issues

puppet-lint fails with NoMethodError: undefined method `[]' for nil:NilClass when fact names are enclosed in double quotes

Example code:
$test1 = $facts["test1"],

Observed failure:

rake lint
[DEPRECATION] last_comment is deprecated. Please use last_description instead.
rake aborted!
NoMethodError: undefined method []' for nil:NilClass /Library/Ruby/Gems/2.0.0/gems/puppet-lint-legacy_facts-check-0.0.2/lib/puppet-lint/plugins/legacy_facts.rb:92:in block in check'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-legacy_facts-check-0.0.2/lib/puppet-lint/plugins/legacy_facts.rb:86:in each' /Library/Ruby/Gems/2.0.0/gems/puppet-lint-legacy_facts-check-0.0.2/lib/puppet-lint/plugins/legacy_facts.rb:86:in check'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/checkplugin.rb:21:in run' /Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/checks.rb:58:in block in run'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/checks.rb:56:in each' /Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/checks.rb:56:in run'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint.rb:191:in run' /Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/tasks/puppet-lint.rb:79:in block (3 levels) in define'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/tasks/puppet-lint.rb:77:in each' /Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/tasks/puppet-lint.rb:77:in block (2 levels) in define'
/Library/Ruby/Gems/2.0.0/gems/puppet-lint-2.1.0/lib/puppet-lint/tasks/puppet-lint.rb:71:in block in define' /Library/Ruby/Gems/2.0.0/gems/rake-11.3.0/exe/rake:27:in <top (required)>'
Tasks: TOP => lint
(See full trace by running task with --trace)

Facts not fixed correctly

Sorry for vague subject, can't think of a better one right now:)

I'm running VS Code puppet addon and some old modules are still using old facts which plugin tried to fix.

Example code:

class test::params {
  case $facts['os']['family'] {
    'RedHat': {
      case $facts['os']['release']['major'] {
        '6': {}
        default: {
          fail("${::osfamily} ${::operatingsystemmajrelease} based systems.")
        }
      }
    }
    default: {}
  }
}

This old facts get fixed to ${facts['facts['os']['family']'] which is obviously wrong.

VS Code says Puppet(legacy_facts) plugins is raising an error and the only plugin with that name I could find was this one. I hope this is the correct repo for filing this issue.

Let me know if you need more info and which.

Adoption in to default puppet-lint plugins

Hey @mmckinst, hope you are doing well!

We recently asked, if it would be OK to adopt your top_scope_facts_check in to puppet-lint as a default plugin.

Would you be happy for us to adopt this one too? I'd ensure that credit was given in the migrated code!

Additionally, the license would change to MIT given that is what puppet-lint currently uses.

Thank you!

false positive with fact in map function.

With puppet-lint-legacy_facts-check (1.0.3)

The following

$_generic_maps = $email_with_fqdn.map | $_user | { "${_user}@cern.ch ${_user}@${facts['fqdn']}" }

reports:

manifests/mta.pp:44:legacy_facts:WARNING:legacy fact

Fix fact mapping

Some facts aren't mapped correctly. Here is a list for those i could figure out:

Wrong: 'gid' => "facts['identity']['gid']"
Correct: 'gid' => "facts['identity']['group']"

Wrong: 'id' => "facts['identity']['uid']"
Correct: 'id' => "facts['identity']['user']"

Wrong: 'lsbdistcodename' => "facts['distro']['codename']"
Correct: 'lsbdistcodename' => "facts['os']['distro']['codename']"

Wrong: 'lsbdistdescription' => "facts['distro']['description']"
Correct: 'lsbdistdescription' => "facts['os']['distro']['description']"

Wrong: 'lsbdistid' => "facts['distro']['id']"
Correct: 'lsbdistid' => "facts['os']['distro']['id']"

Wrong: 'lsbdistrelease' => "facts['distro']['release']['full']"
Correct: 'lsbdistrelease' => "facts['os']['distro']['release']['full']"

Wrong: 'lsbmajdistrelease' => "facts['distro']['release']['major']"
Correct: 'lsbmajdistrelease' => "facts['os']['distro']['release']['major']"

Wrong: 'lsbminordistrelease' => "facts['distro']['release']['minor']"
Correct: 'lsbminordistrelease' => "facts['os']['distro']['release']['minor']"

Wrong: 'lsbrelease' => "facts['distro']['release']['specification']"
Correct: 'lsbrelease' => "facts['os']['distro']['release']['specification']"

I will open up a PR fixing this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.