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

Add exec_restorecon to hiera calls #243

Merged
merged 5 commits into from
Nov 30, 2017
Merged

Conversation

FStelzer
Copy link
Contributor

Also add type definitions for hiera values and replace hiera_hash with the new lookup variant (fixing #238)

Also add type definitions for hiera values and replace hiera_hash with the new lookup variant (fixing voxpupuli#238)
Copy link
Contributor

@vinzent vinzent left a comment

Choose a reason for hiding this comment

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

Hi Fabian

Thanks for your contribution. If you move the lookup_options to hiera data itself this can be merged IMHO:

$module = undef,
$permissive = undef,
$port = undef,
Optional[Hash] $boolean = lookup('selinux::boolean', { 'default_value' => undef, 'merge' => 'hash' }),
Copy link
Contributor

Choose a reason for hiding this comment

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

this does not work IMHO. lookup() will never be used because automatic parameter lookup will see selinux::boolean defined and then the default is not applicable. The defaults for the lookup need to be defined in hiera data itself. see https://puppet.com/docs/puppet/5.0/hiera_merging.html#configuring-merge-behavior-in-hiera-data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. i think you're right.
But i'm not sure what a good solution would be.

Would lookup options defined in a module hiera be actually used if hiera finds the key in global/environment hiera? I would be surprised if it did.

Normally i would simply remove the merge options and leave that up to the user. But that might break backwards compatibility in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, forget what i wrote ;)
i've looked up the documentation and lookup_options is a special case for which puppet actually does a merge to cover this use-case we have here explicitly.

i'll add it to hiera

$module = undef,
$permissive = undef,
$port = undef,
Optional[Hash] $boolean = undef,
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 make sense (and work) to just make this (and the other ones below it) Hash $boolean = {} and still use hiera?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't be a problem and i prefer to have simple datatypes too. But it would break for users explicitly passing "undef" to the class (to override hiera values from higher up) which would no longer be valid (no idea if anyone actually does this).

Copy link
Member

Choose a reason for hiding this comment

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

That's a valid point

Copy link
Contributor

Choose a reason for hiding this comment

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

does passing undef work to not trigger automatic parameter lookup? I think there was a discussion about that some time ago.

But I prefer undef over an empty hash as it shows that nothing needs to be passed and Optional describes this.

Copy link
Contributor

@vinzent vinzent left a comment

Choose a reason for hiding this comment

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

i've run the acceptance tests . they don't use hiera data but at least it doesn't break passing things by param. 👍

@FStelzer
Copy link
Contributor Author

yeah, the hiera data stuff is always hard to test properly... (especially if it involves merge strategies)
i'll try to do a more complex test with hiera later today and let you know

@FStelzer
Copy link
Contributor Author

ok. so hiera also works as expected. tested the hash merge as well

If i'd like to change the default values of the exec_restorecon define how would i implement that?
For example in our case i wanna always have refreshonly => false and have an onlyif with a restorecon -n to basically make sure the contexts are correct on every puppet run for certain directories.

As exec_restorecon is a define and the params get hash merged i can't set defaults via hiera. And the onlyif default is even trickier as it would include the the path as well...
Would you accept a pull request doing something like the following:

  • Add explicit hiera lookups to the define on sth like 'selinux::exec_restorecon::defaults' to change things like the refreshonly value.
  • Add a new parameter like 'Boolean $onlyif_contexts_change = lookup("selinux::exec_restorecon::defaults::onlyif_contexts_change")' that would automatically create an onlyif condition using restorecon -n

But i'm open for other ideas.

@vinzent
Copy link
Contributor

vinzent commented Nov 30, 2017

ok. so hiera also works as expected. tested the hash merge as well

If i'd like to change the default values of the exec_restorecon define
how would i implement that?

You would define a resource default:
https://puppet.com/docs/puppet/5.3/lang_defaults.html

Selinux::Exec_restorecon {
refreshonly => false
}

somewhere on top or node scope. ("$env/manifest/site.pp")

@vinzent vinzent merged commit 61f9a3f into voxpupuli:master Nov 30, 2017
@FStelzer
Copy link
Contributor Author

Ah right. Didn't think about that. Thanks!

Still the onlyif_contexts_change or 'exec_on_changes' would be a nice addition. Otherwise you'll have a puppet exec show up in the logs on every run no matter if it had to change contexts or not.

@FStelzer FStelzer deleted the patch-1 branch November 30, 2017 12:44
@vinzent vinzent mentioned this pull request Dec 15, 2017
EmRowlands pushed a commit to EmRowlands/puppet-selinux that referenced this pull request Mar 29, 2023
Add exec_restorecon to hiera calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants