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

set default values for different puppet versions #202

Merged
merged 5 commits into from
Dec 8, 2017
Merged

set default values for different puppet versions #202

merged 5 commits into from
Dec 8, 2017

Conversation

sartiran
Copy link
Collaborator

@sartiran sartiran commented Dec 1, 2017

This PR goes with quattor/configuration-modules-core#1201 the components and schema have been updated to be compliant with the most recent versions of puppet. I've just introduced a default.pan template managing the different default values corresponding to different versions.

}else{
version = PUPPET_VERSION;
};
};
Copy link
Member

Choose a reason for hiding this comment

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

This might be neater:

variable PUPPET_VERSION ?= '3.0.0';

'/software/components/puppet' = {
    version = PUPPET_VERSION;
    version = replace('^([0-9]+)$', '$1.0', version); #Pad single to double
    version = replace('^([0-9]+\.[0-9]+)$', '$1.0', version); # Pad double to triple
…etc…

Copy link
Member

Choose a reason for hiding this comment

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

In fact this shouldn't be necessary if you are only using if for the comparisons later on, pkg_compare_version should handle this for you.


'/software/packages/{puppet}' ?= nlist();
'/software/packages/{puppet}' ?= dict();
Copy link
Member

Choose a reason for hiding this comment

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

pkg_repl() is preferred.

'/software/packages' = pkg_repl('puppet');


# Defaults for version > 4
if(pkg_compare_version(version, '4.0.0') != PKG_VERSION_LESS){
SELF['hieraconf_file'] = '/etc/puppetlabs/code/environments/production/hiera.yaml';
Copy link
Member

Choose a reason for hiding this comment

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

Try to avoid operating on SELF like this. It might actually be nicer to adapt this to instead include a defaults file for each major version, but it's up to you.

Perhaps something like:

include if (pkg_compare_version(PUPPET_VERSION, '4.0.0') != PKG_VERSION_LESS) 'features/puppet/defaults_4+';
include if (pkg_compare_version(PUPPET_VERSION, '5.0.0') != PKG_VERSION_LESS) 'features/puppet/defaults_5+';
template features/puppet/defaults_4+;

include 'components/puppet/config';

prefix '/software/components/puppet';
'hieraconf_file' = '/etc/puppetlabs/code/environments/production/hiera.yaml';
'puppet_cmd' = '/opt/puppetlabs/bin/puppet';
'puppetconf_file' = '/etc/puppetlabs/puppet/puppet.conf';
template features/puppet/defaults_5+;

include 'components/puppet/config';

prefix '/software/components/puppet';

'nodefiles/{quattor_default.pp}/contents' = "lookup('classes', Array[String], 'unique').include",

'modulepath' = '/etc/puppetlabs/code/environments/production/modules';

'nodefiles_path' = '/etc/puppetlabs/code/environments/production/manifests';

"hieraconf" = dict(
    "version", 5,
    "hierarchy", list(
        dict(
            "name", "quattor",
            "path", "quattor.yaml",
        )
    ),
    "defaults", dict(
        "datadir", "/etc/puppetlabs/code/environments/production/data",
        "data_hash", "yaml_data",
    ),
);

'hieradata_file' = '/etc/puppetlabs/code/environments/production/data/quattor.yaml';

@sartiran
Copy link
Collaborator Author

sartiran commented Dec 7, 2017

Hi James, I've tried to implement all your recommendations. Actually I cannot define to a standard value PUPPET_VERSION in the defaults template as it seems that this template is called one first time before the site's defaults are set (and fixing the variable would imply that the sites cannot have a define+fallback setup). Changing this would require touching a lot of other stuff and I'd prefer not to. Thus I've implemented this in a slightly different way wrt what you suggested.


include 'components/puppet/config';

variable PUPPET_4_INCLUDE = is_defined(PUPPET_VERSION) &&
Copy link
Member

Choose a reason for hiding this comment

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

Would it be acceptable to provide a default Puppet version to avoid having to check for it being defined?

For example:

variable PUPPET_VERSION ?= '3.0.0';

Copy link
Member

Choose a reason for hiding this comment

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

Ok I see your comment, nevermind.

Copy link
Member

@jrha jrha left a comment

Choose a reason for hiding this comment

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

LGTM, I presume you've tested this!

@sartiran
Copy link
Collaborator Author

sartiran commented Dec 7, 2017

Sorry, I had to add a modification. It seems that pkg_compare_version does not handle comparing versions which are not in the X.Y.Z format. So I've re-introduced the PUPPET_VERSION formatting in the default template.

@jrha
Copy link
Member

jrha commented Dec 8, 2017

Ok, my apologies, my testing seemed to indicate that it worked!

@jrha jrha added this to the 17.12 milestone Dec 8, 2017
@jrha jrha merged commit 2798176 into quattor:umd-3 Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants