Jira (PUP-9750) optionally add pe_version to server_facts

18 views
Skip to first unread message

Thomas Kishel (JIRA)

unread,
Jun 12, 2019, 3:18:04 PM6/12/19
to puppe...@googlegroups.com
Thomas Kishel created an issue
 
Puppet / Improvement PUP-9750
optionally add pe_version to server_facts
Issue Type: Improvement Improvement
Assignee: Unassigned
Created: 2019/06/12 12:17 PM
Priority: Normal Normal
Reporter: Thomas Kishel

Members of the Puppet Community have requested a standardized best practice to determine if a Puppet Agent is a PE or FOSS Puppet Agent. Since Puppet 4.x, there is no concept of a PE or FOSS Puppet Agent, but a Puppet Agent can be served a catalog by a PE or FOSS Puppet Server.

A non-empty pe_version fact would both differentiate between PE or FOSS, but would allow for conditional code depending upon the specific version of PE.

The pe_version fact is available in Puppet / PE 3.x.

The pe_compiling_server_version function (which calls pe_server_version) is available on a PE Puppet Server after PE 3.x, but is not available on a FOSS Puppet Server, requiring the use of the is_function_available} function to avoid generating an error when calling {{pe_compiling_server_version function on a FOSS Puppet Server.

The is_function_available function is itself now deprecated.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Thomas Kishel (JIRA)

unread,
Jun 12, 2019, 3:30:03 PM6/12/19
to puppe...@googlegroups.com
Thomas Kishel commented on Improvement PUP-9750
 
Re: optionally add pe_version to server_facts

If this PR is approved (and added to Puppet 7) then we could add this function to puppetlabs-stdlib ...

# This needs to be a function rather than updating the 3.x `pe_version` fact.
#
# In Puppet 3.x, PE is a property of the agent.
# In Puppet 4.x and newer, PE is a property of the compiling master.
# In Puppet 4.x to 6.x, inspect the `pe_version` file on the compiling master.
# In Puppet 7.x and newer, inspect server_facts['pe_version'].
 
Puppet::Functions.create_function(:get_pe_version) do
  def get_pe_version
    scope = closure_scope
    facts = scope['facts']
 
    if Puppet::Util::Package.versioncmp(facts['puppetversion'], '3.9.9') < 0
      return facts['pe_version']
    end
 
    if Puppet::Util::Package.versioncmp(facts['puppetversion'], '6.9.9') < 0
      pe_version_file = '/opt/puppetlabs/server/pe_version'
      if File.readable?(pe_version_file) and !File.zero?(pe_version_file)
        pe_version_data = File.read(pe_version_file).chomp
        pe_version = pe_version_data.match(/(\d+\.\d+\.\d+)/)
        return pe_version[1] if pe_version
      end
    else
      server_facts = scope['server_facts']
      return server_facts['pe_version']
    end
 
    nil
  end
end

Instead of this PR, we could just add this function (minus inspecting server_facts) if Puppet 4x+) to puppetlabs-stdlib.

But it feels like pe_version is a valid server_fact.

Thomas Kishel (JIRA)

unread,
Jun 13, 2019, 5:17:04 PM6/13/19
to puppe...@googlegroups.com
Thomas Kishel commented on Improvement PUP-9750

This sets server_facts['pe_version'] which sets/overrides the pe_version fact ... but only in the catalog compiled by the server:

[root@pe-201818-master ~]# cat /etc/puppetlabs/code/environments/production/manifests/site.pp
node default {
  $gpev = get_pe_version()
  if $gpev { notify { "PE Version ${gpev} | ${server_facts['pe_version']} | ${pe_version}": } }
}

[root@pe-201818-agent ~]# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for pe-201818-agent.puppetdebug.vlan
Info: Applying configuration version '1560459967'
Notice: PE Version 2018.1.8 | 2018.1.8 | 2018.1.8
Notice: /Stage[main]/Main/Node[pe-201818-agent.puppetdebug.vlan]/Notify[PE Version 2018.1.8 | 2018.1.8 | 2018.1.8]/message: defined 'message' as 'PE Version 2018.1.8 | 2018.1.8 | 2018.1.8'
Notice: Applied catalog in 0.03 seconds

... even if the puppetlabs-stdlib module is installed.
Again, but only in the catalog compiled by the server:

[root@pe-201818-agent ~]#  facter -p | grep 2018.1.8
<crickets>

Given the various fact names available on a compiling (PE) master:

[root@pe-201818-master ~]# facter -p | grep 2018.1.8
pe_build => 2018.1.8
pe_server_version => 2018.1.8

And the fact names in the puppetlabs-stdlib module:

is_pe
pe_version
pe_major_version
pe_minor_version
pe_patch_version

And the function names in PE:

pe_compiling_server_version
pe_server_version

We should carefully consider the name of this server_facts key in regard to simplification and backward compatibility.

Thomas Kishel (JIRA)

unread,
Jun 14, 2019, 6:36:02 PM6/14/19
to puppe...@googlegroups.com
Thomas Kishel commented on Improvement PUP-9750

See also: https://puppet.com/docs/puppet/latest/lang_facts_and_builtin_vars.html#serverfacts-variable

`serverversion` is the current version of Puppet on the Puppet master, so maybe server_facts['pe_version' should be server_facts['peserverversion` ?

That would avoid a collision with the PE fact or function names, and the fact names in the puppetlabs-stdlib module.

Jorie Tappa (JIRA)

unread,
Jun 17, 2019, 12:50:03 PM6/17/19
to puppe...@googlegroups.com
Jorie Tappa updated an issue
 
Change By: Jorie Tappa
Team: Coremunity

Thomas Kishel (JIRA)

unread,
Aug 23, 2019, 12:20:03 PM8/23/19
to puppe...@googlegroups.com
Thomas Kishel commented on Improvement PUP-9750
 
Re: optionally add pe_version to server_facts

Switched to `peserverversion` to match the other keys in server_facts, which do not use underscores.

Reverting would be a trivial search and replace.

Josh Cooper (JIRA)

unread,
Oct 30, 2019, 2:20:03 AM10/30/19
to puppe...@googlegroups.com
Josh Cooper updated an issue
 
Change By: Josh Cooper
Sprint: Coremunity Hopper

Josh Cooper (JIRA)

unread,
Oct 30, 2019, 2:25:04 AM10/30/19
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Sprint: Coremunity Hopper Community PRs

Josh Cooper (JIRA)

unread,
Jan 21, 2020, 5:10:04 PM1/21/20
to puppe...@googlegroups.com
Josh Cooper updated an issue
Members of the Puppet Community have requested a standardized best practice to determine if a Puppet Agent is a PE or FOSS Puppet Agent. Since Puppet 4.x, there is no concept of a PE or FOSS Puppet Agent, but a Puppet Agent can be served a catalog by a PE or FOSS Puppet Server.

A non-empty {{pe_version}} fact would both differentiate between PE or FOSS, but would allow for conditional code depending upon the specific version of PE.


The {{pe_version}} fact is available in Puppet / PE 3.x.


The {{pe_compiling_server_version}} function (which calls {{pe_server_version}}) is available on a PE Puppet Server after PE 3.x, but is not available on a FOSS Puppet Server, requiring the use of the {{is_function_available} } function to avoid generating an error when calling {{pe_compiling_server_version}} function on a FOSS Puppet Server.



The {{is_function_available}} function is itself now deprecated.

Rob Braden (JIRA)

unread,
Feb 3, 2020, 12:58:04 PM2/3/20
to puppe...@googlegroups.com
Rob Braden updated an issue
Change By: Rob Braden
Release Notes: Enhancement

Rob Braden (JIRA)

unread,
Feb 3, 2020, 12:59:04 PM2/3/20
to puppe...@googlegroups.com
Rob Braden commented on Improvement PUP-9750
 
Re: optionally add pe_version to server_facts

The final name is pe_serverversion

Reply all
Reply to author
Forward
0 new messages