From ecff69b07533a65dd5aff743c7b3046e5c8a06f6 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Wed, 18 Oct 2023 08:13:12 +0200 Subject: [PATCH] psick::puppet::facter profile and minor updates --- CHANGELOG.md | 5 +++ data/windows.yaml | 3 +- docs/hosts.md | 6 +-- manifests/admin.pp | 56 ++++++++++++++++++++++++- manifests/hostname.pp | 2 +- manifests/init.pp | 2 +- manifests/network/example42.pp | 8 ++-- manifests/network/interface.pp | 2 +- manifests/puppet/facter.pp | 49 ++++++++++++++++++++++ metadata.json | 28 +++++++++---- spec/classes/puppet/facter_spec.rb | 13 ++++++ templates/puppet/facter/facter.conf.epp | 28 +++++++++++++ 12 files changed, 181 insertions(+), 21 deletions(-) create mode 100644 manifests/puppet/facter.pp create mode 100644 spec/classes/puppet/facter_spec.rb create mode 100644 templates/puppet/facter/facter.conf.epp diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b4a36ad..e4ffe306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +## Release 1.1.0 + +- More updates for Puppet 8 compatibility +- Added psick::puppet::facter profile to manage facter.conf + ## Release 1.0.4 - Updated psick::timezone to support more recent Debian derivatives diff --git a/data/windows.yaml b/data/windows.yaml index 764e49ce..80b3dbc6 100644 --- a/data/windows.yaml +++ b/data/windows.yaml @@ -3,4 +3,5 @@ psick::puppet::pe_agent::config_file_path: 'c:/programdata/puppetlabs/puppet/etc psick::puppet::postrun::puppet_conf_path: 'c:/programdata/puppetlabs/puppet/etc/puppet.conf' psick::puppet::pe_client_tools::repo_path: 'windows' psick::puppet::pe_client_tools::package_suffix: '-x64.msi' -psick::puppet::pe_client_tools::package_download_dir: 'c:/tmp' \ No newline at end of file +psick::puppet::pe_client_tools::package_download_dir: 'c:/tmp' +psick::puppet::facter::config_file_dir: 'c:/programdata/puppetlabs/facter/etc' diff --git a/docs/hosts.md b/docs/hosts.md index 616fb258..b579b14c 100644 --- a/docs/hosts.md +++ b/docs/hosts.md @@ -5,8 +5,8 @@ psick::hosts::file class manages /etc/hosts To customise its behaviour you can set the template to use to manage ```/etc/hosts```, and the ipaddress, domain and hostname values for the local node (by default the relevant facts values are used): psick::hosts::file::template: 'psick/hosts/file/hosts.erb' # Default value - psick::hosts::file::ipaddress: '10.0.0.4' # Default: $::ipaddress - psick::hosts::file::domain: 'domain.com' # Default: $::domain - psick::hosts::file::hostname: 'www01' # Default: $::hostname + psick::hosts::file::ipaddress: '10.0.0.4' # Default: $::networking['ip'] + psick::hosts::file::domain: 'domain.com' # Default: $::networking['domain'] + psick::hosts::file::hostname: 'www01' # Default: $::networking['hostname'] diff --git a/manifests/admin.pp b/manifests/admin.pp index f6ec1505..e696d72b 100644 --- a/manifests/admin.pp +++ b/manifests/admin.pp @@ -1,4 +1,58 @@ -# @class admin +# This class manages an admin user and SSH access on Puppet managed nodes. +# +# == Parameters +# +# [*ensure*] +# Whether the admin user should be present or absent. Defaults to `present`. +# +# [*user_class*] +# The name of the class that manages the admin user on infrastructure nodes. Defaults to `::psick::admin::user`. +# Note: If default is changed other params of this class might not be used. +# +# [*master_class*] +# The name of the class that manages the central master node from which ssh access is granted. Defaults to `::psick::admin::master`. +# Note: If default is changed other params of this class might not be used. +# +# [*node_class*] +# The name of the class that manages nodes which allow access from master node. Defaults to `::psick::admin::node`. +# Note: If default is changed other params of this class might not be used. +# +# [*user*] +# The name of the admin user. Defaults to `admin`. +# +# [*master*] +# The hostname or IP address of the master node. Defaults to `''`. +# +# [*keyshare_method*] +# The method used to share SSH keys between nodes and the master node. Defaults to `storeconfigs`. +# +# [*auto_prereq*] +# Whether to automatically include prerequisite classes. Defaults to the value of `$psick::auto_prereq`. +# +# [*master_enable*] +# Whether to enable master management. If true, master class is included and node is a master. Defaults to `false`. +# +# [*node_enable*] +# Whether to enable node management. If true, node class is included and node can bve controlled from master. Defaults to `true`. +# +# [*manage*] +# Whether to manage any resource on this class. Defaults to the value of `$psick::manage`. +# +# [*noop_manage*] +# Whether to manage noop for this class resources. Defaults to the value of `$psick::noop_manage`. +# +# [*noop_value*] +# The value to use for noop mode. Defaults to the value of `$psick::noop_value`. +# +# == Example +# +# To manage the admin user and SSH access from master node, just include the `psick::admin` class: +# +# include psick::admin +# +# Via Hiera on the master node set: +# +# psick::admin::master_enable: true # class psick::admin ( diff --git a/manifests/hostname.pp b/manifests/hostname.pp index 339927fe..6679fdcf 100644 --- a/manifests/hostname.pp +++ b/manifests/hostname.pp @@ -43,7 +43,7 @@ if $update_host_entry { host { $host: ensure => present, - host_aliases => $fqdn, + host_aliases => $::networking['fqdn'], ip => $ip, } } diff --git a/manifests/init.pp b/manifests/init.pp index 4bfd869e..0e11c6c8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -134,7 +134,7 @@ Enum['first','hash','deep'] $resources_merge_behaviour = 'deep', Enum['first','hash','deep'] $resources_defaults_merge_behaviour = 'deep', - # $::osfamily based resources + # $::os['family'] based resources # Hash $osfamily_resources (lookup with $osfamily_resources_merge_behaviour) = {}, # Hash $osfamily_resources_defaults (lookup with $osfamily_resources_defaults_merge_behaviour) = {}, Enum['first','hash','deep'] $osfamily_resources_merge_behaviour = 'deep', diff --git a/manifests/network/example42.pp b/manifests/network/example42.pp index 78c1d325..6d8bee41 100644 --- a/manifests/network/example42.pp +++ b/manifests/network/example42.pp @@ -8,10 +8,10 @@ # for the file /etc/sysconfig/network # @param routes Hash of routes to pass to ::network::mroute define # Note: This is not a real class parameter but a key looked up -# via hiera_hash('psick::network::routes', {}) +# via lookup('psick::network::routes', Hash, 'deep', {}) # @param interfaces Hash of interfaces to pass to ::network::interface define # Note: This is not a real class parameter but a key looked up -# via hiera_hash('psick::network::interfaces', {}) +# via lookup('psick::network::interfaces', Hash, 'deep', {}) # Note that this psick automatically adds some default # options according to the interface type. You can override # them in the provided hash @@ -23,7 +23,7 @@ file { '/etc/modprobe.d/bonding.conf': ensure => file, } - $routes = hiera_hash('psick::network::routes', {}) + $routes = lookup('psick::network::routes', Hash, 'deep', {}) $routes.each |$r,$o| { psick::network::route { $r: routes => $o[routes], @@ -45,7 +45,7 @@ bonding_opts => "resend_igmp=1 updelay=30000 use_carrier=1 miimon=100 downdelay=100 xmit_hash_policy=0 primary_reselect=0 fail_over_mac=0 arp_validate=0 mode=${bonding_mode} arp_interval=0 ad_select=0", bonding_master => 'yes', } - $interfaces = hiera_hash('psick::network::interfaces', {}) + $interfaces = lookup('psick::network::interfaces', Hash, 'deep', {}) $interfaces.each |$r,$o| { if $r =~ /^bond/ { $options = $default_options + $default_bonding_options + $o diff --git a/manifests/network/interface.pp b/manifests/network/interface.pp index 7f2cf5fa..9987b5bd 100644 --- a/manifests/network/interface.pp +++ b/manifests/network/interface.pp @@ -17,7 +17,7 @@ # # @param ensure If to create or remove the relevant configuration file. # @param template The epp or erb template to use for the interface configuration -# file. Default is automatically defined based on $::osfamily, +# file. Default is automatically defined based on $::os['family'], # @param config_path The path of the interface configuration file. # Default is automatically defined based on the Operating System. # @param enable_dhcp If to configure the interface to use dhcp. diff --git a/manifests/puppet/facter.pp b/manifests/puppet/facter.pp new file mode 100644 index 00000000..5270ba77 --- /dev/null +++ b/manifests/puppet/facter.pp @@ -0,0 +1,49 @@ +# @summary A short summary of the purpose of this class +# +# A description of what this class does +# +# @example +# include psick::puppet::facter +class psick::puppet::facter ( + Psick::Ensure $ensure = 'present', + Boolean $manage = $psick::manage, + Boolean $noop_manage = $psick::noop_manage, + Boolean $noop_value = $psick::noop_value, + String $config_file_dir = '/etc/puppetlabs/facter', + String $config_file_template = 'psick/puppet/facter/facter.conf.epp', + Hash $cli_settings = {}, + Hash $global_settings = {}, + Hash $fact_groups = {}, + Array[String] $blocklist = [], + Array[Hash] $ttls = [], +) { + if $manage { + if $noop_manage { + noop($noop_value) + } + $parameters = { + cli_settings => $cli_settings, + global_settings => $global_settings, + fact_groups => $fact_groups, + blocklist => $blocklist, + ttls => $ttls, + } + if $cli_settings != {} + or $global_settings != {} + or $fact_groups != {} + or $blocklist != [] + or $ttls != [] { + psick::tools::create_dir { "psick::puppet::facter ${config_file_dir}": + path => $config_file_dir, + before => File["${config_file_dir}/facter.conf"], + } + file { "${config_file_dir}/facter.conf": + ensure => $ensure, + owner => 'root', + group => 'root', + mode => '0644', + content => psick::template($config_file_template,$parameters), + } + } + } +} diff --git a/metadata.json b/metadata.json index b558e114..09742d8b 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "example42-psick", - "version": "1.0.4", + "version": "1.1.0", "author": "Example42", "summary": "Psick: the infrastructure module.", "license": "Apache-2.0", @@ -10,11 +10,11 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 3.2.0 < 7.0.0" + "version_requirement": ">= 3.2.0 < 10.0.0" }, { "name": "example42/tp", - "version_requirement": ">= 2.0.3 < 4.0.0" + "version_requirement": ">= 2.0.3 < 5.0.0" }, { "name": "example42/psick_profile", @@ -30,21 +30,24 @@ "operatingsystem": "RedHat", "operatingsystemrelease": [ "6", - "7" + "7", + "8" ] }, { "operatingsystem": "CentOS", "operatingsystemrelease": [ "6", - "7" + "7", + "8" ] }, { "operatingsystem": "OracleLinux", "operatingsystemrelease": [ "6", - "7" + "7", + "8" ] }, { @@ -57,13 +60,20 @@ { "operatingsystem": "Debian", "operatingsystemrelease": [ - "8" + "8", + "9", + "10", + "11", + "12" ] }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ - "16.04" + "16.04", + "18.04", + "20.04", + "22.04" ] }, { @@ -79,7 +89,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 4.5.0 < 8.0.0" + "version_requirement": ">= 4.5.0 < 9.0.0" } ], "description": "Psick Puppet module. A single module to manage an extendable Puppet infrastructure", diff --git a/spec/classes/puppet/facter_spec.rb b/spec/classes/puppet/facter_spec.rb new file mode 100644 index 00000000..e18b97a2 --- /dev/null +++ b/spec/classes/puppet/facter_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'psick::puppet::facter' do + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile.with_all_deps } + end + end +end diff --git a/templates/puppet/facter/facter.conf.epp b/templates/puppet/facter/facter.conf.epp new file mode 100644 index 00000000..3ff9a221 --- /dev/null +++ b/templates/puppet/facter/facter.conf.epp @@ -0,0 +1,28 @@ +# File managed by Puppet +facts : { + blocklist : <%= $blocklist %> + ttls : [ + <% $ttls.each | $k | {-%> + <% $k.each | $kk, $vv | { -%> + { "<%= $kk %>" : <%= $vv %> }, + <% } -%> + <% } -%> + ] +} +global : { +<% $global_settings.each | $k,$v | { -%> + <%= $k %> : <%= $v %>, +<% } -%> +} +cli : { +<% $cli_settings.each | $k,$v | { -%> + <%= $k %> : <%= $v %>, +<% } -%> +} +fact-groups : { +<% $fact_groups.each | $k | { -%> + <% $k.each | $kk | { -%> + <%= $k %> : <%= $kk %>, + <% } -%> +<% } -%> +}