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

Added parameter sensu::install_repo as the first condition to manage … #475

Merged
merged 1 commit into from
Feb 29, 2016

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Feb 12, 2016

Currently, if a user does not want to install the repositories by setting the parameter class install_repo to false, and this is declared in hiera, there is an error about duplicated resources apt::source (resource declared in manifests/repo/apt.pp file).

This PR changes the checks of the if statement to avoid this error about duplicated resources.

@jlambert121
Copy link
Contributor

Where is the second declaration of apt::source{ 'sensu': }? Are you declaring it in your manifests as well? The module intentionally declares it so it can remove the repo if you don't want it and should be just settingensure => 'absent'` on the repo itself.

@mrodm
Copy link
Contributor Author

mrodm commented Feb 15, 2016

I've defined this resource using hiera and create_resources.
The problem is that once the resource is defined by that file as ensure => absent (by setting $sensu::install_repo = false), I cannot define it by hiera.

The check of this PR is as it is performed for yum repos.

@jlambert121
Copy link
Contributor

The packages create a repo with the name of sensu and setting install_repo ensures they get removed. If you'd like to define your own sensu repository, you'll need to name it something other than sensu.

@mrodm
Copy link
Contributor Author

mrodm commented Feb 23, 2016

That's true, I could change just the name of the resource in hiera to solve the duplicated resource, but I did not explained myself well above.
This error appears because I need to manage apt packages/repositories by means of stages. My stages are defined as:

stage{ 'provisioning': }
Stage['provisioning'] -> Stage['main']
class { 'apt': stage => 'provisioning' }

In this way, the definition of this resource in the sensu module produces a circular dependency when used with stages, even when it is declared as absent by means of setting $sensu::install_repo = false.

This PR tries to solved this circular dependency by avoiding the declaration of the apt resource when the parameter install_repo is set to false.

@eholzbach
Copy link

I just hit the same issue today.

@jlambert121
Copy link
Contributor

I'm not a fan of removing the management of the repo if install_repo is false because then the repo installed with the package never gets removed.

For your stage setup, what about just adding

Apt { stage => 'provisioning' }

@mrodm
Copy link
Contributor Author

mrodm commented Feb 25, 2016

I'm thinking in another option to keep both approaches.
It could be added another boolean parameter to the module named "manage_repo" with default value true.

class sensu (
...
$manage_repo = true,
...

This new parameter 'manage_repo' would handle the apt resource definition and install_repo will keep enabling or removing the new repo as previously. Adding this parameter will allow us to break the circular dependency when stages are used if it is redefined by means of hiera.

if $sensu::manage_repo {
  if defined(apt::source) {

    $ensure = $sensu::install_repo ? {
      true    => 'present',
      default => 'absent'
    }

    if $sensu::repo_source {
      $url = $sensu::repo_source
    } else {
      $url = 'http://repos.sensuapp.org/apt'
    }

    apt::source { 'sensu':
      ensure   => $ensure,
      location => $url,
      release  => 'sensu',
      repos    => $sensu::repo,
      include  => {
        'src' => false,
      },
      key      => {
        'id'     => $sensu::repo_key_id,
        'source' => $sensu::repo_key_source,
      },
      before   => Package['sensu'],
    }

@jlambert121
Copy link
Contributor

I could go for that. I don't like adding additional (potentially confusing) parameters, but I understand the problem and can't think of anything else. Could you wrap the yum repo as well with it?

@mrodm
Copy link
Contributor Author

mrodm commented Feb 25, 2016

Thanks!
I'll do the change for yum repo too and I'll update this PR.

@jlambert121
Copy link
Contributor

Perfect! If you get this in the next day or two I'll get it in the next release I need to push up.

@mrodm mrodm force-pushed the check_apt_source_install branch 2 times, most recently from 43ffd50 to 8498410 Compare February 26, 2016 16:42
@mrodm
Copy link
Contributor Author

mrodm commented Feb 26, 2016

I've updated the PR adding the new variable $manage_repo in two conditions.

About yum, Introducing these changes into yum repos is not an easy task.
Depending on the puppet version, the yumrepo has different behavior. For instance, in puppet 3.3 yumrepo has no ensure parameter and it causes that the tests fail.

@jlambert121
Copy link
Contributor

What about instead of putting it in the repo::type class we just put it in package.pp and avoid the class altogether?

@mrodm
Copy link
Contributor Author

mrodm commented Feb 26, 2016

I'll give it a try

@mrodm
Copy link
Contributor Author

mrodm commented Feb 29, 2016

Updated the PR, moving the condition using sensu::manage_repo to package.pp

@jlambert121
Copy link
Contributor

Awesome! looks a whole lot cleaner. One last request and then I'll merge it and do a release today - can you throw a couple tests in for manage_repo = false and make sure the repo classes aren't included?

@mrodm
Copy link
Contributor Author

mrodm commented Feb 29, 2016

I've added some tests to check the behavior using manage_repo variable

@jlambert121
Copy link
Contributor

Thanks! Release coming shortly as well.

jlambert121 added a commit that referenced this pull request Feb 29, 2016
Added parameter sensu::install_repo as the first condition to manage …
@jlambert121 jlambert121 merged commit ef2b8bd into sensu:master Feb 29, 2016
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