puppetlabs / puppet-lint

Check that your Puppet manifests conform to the style guide

Home Page:https://puppetlabs.github.io/puppet-lint/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Broken manifest on double-fix of a legacy_facts and top_scope_facts

chutzimir opened this issue · comments

Describe the Bug

Fixing two problems on the same segment (reproduced with top_scope_facts and legacy_facts) results in broken code.

Expected Behavior

The result should be either working code, or at least refusal to do it.

Steps to Reproduce

Steps to reproduce the behavior:

  1. echo 'notify { $::hostname: }' > test.pp
  2. puppet lint -f test.pp
FIXED: legacy fact 'hostname' on line 1 (check: legacy_facts)
FIXED: top scope fact instead of facts hash on line 1 (check: top_scope_facts)
  1. cat test.pp
notify { $facts['facts['networking']['hostname']']: }

Environment

  • Version 4.4.0
  • Platform Rocky 9.1

Additional Context

Fixing the code check by check does the right thing. E.g.:

$ cat test.pp
notify { $::hostname: }
$ puppet lint -f --only-checks top_scope_facts test.pp
FIXED: top scope fact instead of facts hash on line 1 (check: top_scope_facts)
$ cat test.pp
notify { $facts['hostname']: }
$ puppet lint -f test.pp
FIXED: legacy fact 'hostname' on line 1 (check: legacy_facts)
$ cat test.pp
notify { $facts['networking']['hostname']: }

Or in one step even:

$ cat test.pp
notify { $::hostname: }
$ puppet lint -f --only-checks legacy_facts test.pp
FIXED: legacy fact 'hostname' on line 1 (check: legacy_facts)
$ cat test.pp
notify { $facts['networking']['hostname']: }

Hi @chutzimir, I believe this issue is a duplicate of #106. It has been resolved in the latest release v4.0.1. If the issue has been resolved, please close this report.

I checked that in the current 4.2.3 release $::hostname is not considered a top scope fact, and is properly fixed as a legacy fact.

E.g.:

$ cat test.pp
notify { $::hostname: }
notify { $::timezone: }

$ puppet lint  test.pp
WARNING: legacy fact 'hostname' on line 1 (check: legacy_facts)
WARNING: top scope fact instead of facts hash on line 2 (check: top_scope_facts)