Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fact() function for all os.distro.* facts #1017

Merged
merged 2 commits into from
Mar 15, 2022

Conversation

root-expert
Copy link

@root-expert root-expert commented Feb 24, 2022

  • On Puppet 6 facter 3.x requires lsb-release to resolve os.distro.* facts which may not always be available. Using $facts hash cause errors like "Evaluation Error: Operator '[]' is not applicable to an Undef Value." because os.distro is undefined causing the catalog to fail. Use fact() to identify Undef facts and throw an error to the user.

Releated:

* On Puppet 6 facter 3.x requires lsb-release to resolve os.distro.* facts. Using $facts hash cause errors like "Evaluation Error: Operator '[]' is not applicable to an Undef Value." because os.distro is undefined causing the catalog to fail. Use fact() to identify Undef facts and throw an error to the user.

Signed-off-by: Christos Papageorgiou <christos.papageorgioy@gmail.com>
@root-expert root-expert requested a review from a team as a code owner February 24, 2022 12:18
@puppet-community-rangefinder
Copy link

apt::backports is a class

Breaking changes to this file WILL impact these 8 modules (exact match):
Breaking changes to this file MAY impact these 1 modules (near match):

apt::ppa is a type

Breaking changes to this file WILL impact these 68 modules (exact match):
Breaking changes to this file MAY impact these 10 modules (near match):

apt::source is a type

Breaking changes to this file WILL impact these 337 modules (exact match):
Breaking changes to this file MAY impact these 88 modules (near match):

This module is declared in 234 of 578 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

@CLAassistant
Copy link

CLAassistant commented Feb 24, 2022

CLA assistant check
All committers have signed the CLA.

kenyon
kenyon previously approved these changes Feb 24, 2022
Copy link
Collaborator

@smortex smortex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum… 🤔 This is a good start but not enough I think.

This is replacing a hard failure with a cryptic error message by no failure (at the puppet level) but a broken configuration (at the apt level) when running on a system without the 'apt-transport-https' package but 'https://' repositories (and all sources will lack a release which is probably not good BTW).

We can't add a dependency on lsb-release at this level since it is needed before the catalog is computed (i.e. already too late).

My guess is that we should rather fail hard with a clear error message when we detect that fact('os.distro.codename') is undef with a message like Cannot determine the distribution codename. Older versions of Facter rely on lsb-release to fetch it, is it installed?. Maybe in the apt class if all classes include it.

What do you think?

@root-expert
Copy link
Author

I don't think it's a cryptic error, it clearly states that a specific parameter must be declared in order for it to work 🤔

It fails to auto-detect the distro so the user must explicitly set it (or install lsb-release)

smortex added a commit to voxpupuli/puppet-elasticsearch that referenced this pull request Mar 6, 2022
smortex added a commit to voxpupuli/puppet-elasticsearch that referenced this pull request Mar 6, 2022
smortex added a commit to voxpupuli/puppet-elasticsearch that referenced this pull request Mar 6, 2022
smortex added a commit to voxpupuli/puppet-elasticsearch that referenced this pull request Mar 6, 2022
@smortex
Copy link
Collaborator

smortex commented Mar 6, 2022

What I call a cryptic error message is the following when adding a random resource:

  Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Operator '[]' is not applicable to an Undef Value. (file: /etc/puppetlabs/code/environments/production/modules/apt/manifests/source.pp, line: 102, column: 9) (file: /etc/puppetlabs/code/environments/production/modules/elastic_stack/manifests/repo.pp, line: 71) on node ubuntu1804-64.example.com

While the root problem is that a package is missing.

As it is right now, the PR fix the catalog but I can imagine cases where this will produce broken apt config. I did a test for the above module but it seems to be okay (voxpupuli/puppet-elasticsearch#1149) so maybe I am paranoid? 🤷 😄

@kenyon
Copy link

kenyon commented Mar 8, 2022

@smortex in that elasticsearch test run, why is it complaining about source.pp line 102? That's just a variable assignment. 🤔

@smortex
Copy link
Collaborator

smortex commented Mar 8, 2022

@smortex in that elasticsearch test run, why is it complaining about source.pp line 102? That's just a variable assignment. thinking

Line 102 in the latest release, but line 103 on main ATM:

if ($facts['os']['distro']['codename'] in $_transport_https_releases) and $_location =~ /(?i:^https:\/\/)/ {

Without lsb-release, with facter 3, $facts['os']['distro'] is undef

@root-expert
Copy link
Author

@smortex in that elasticsearch test run, why is it complaining about source.pp line 102? That's just a variable assignment. thinking

Line 102 in the latest release, but line 103 on main ATM:

if ($facts['os']['distro']['codename'] in $_transport_https_releases) and $_location =~ /(?i:^https:\/\/)/ {

Without lsb-release, with facter 3, $facts['os']['distro'] is undef

Ah I see you point. Yea that was the only part which the module doesn't fail. Failing directly on the apt class maybe it's too harsh? I would maybe opt out to fail per-class although not a strong opinion here.

Copy link
Collaborator

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a typo, other than that 👍

manifests/source.pp Outdated Show resolved Hide resolved
if $facts['os']['distro']['codename'] {
$_release = $facts['os']['distro']['codename']
if fact('os.distro.codename') {
$_release = fact('os.distro.codename')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very strictly speaking, this line doesn't need to be modified since at this point you know it's available. But it works too.

Signed-off-by: Christos Papageorgiou <christos.papageorgioy@gmail.com>
@ekohl
Copy link
Collaborator

ekohl commented Mar 15, 2022

A few times I've forgotten to merge after approving but having to wait for the tests. If I do, please ping me.

Copy link
Collaborator

@smortex smortex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this: maybe some edge case still need adjusting but it proves to improve the situation 👍

@smortex smortex merged commit c0f642a into puppetlabs:main Mar 15, 2022
@ekohl ekohl added the bugfix label Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants