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

Confine nginx_version fact #815

Merged
merged 1 commit into from
Jun 23, 2016
Merged

Confine nginx_version fact #815

merged 1 commit into from
Jun 23, 2016

Conversation

ekingme
Copy link
Contributor

@ekingme ekingme commented Jun 8, 2016

If this fact is not confined it will display a dialog on Windows which requires interaction. If puppet runs silently, it will hang.

Fixes #814

@@ -1,4 +1,5 @@
Facter.add(:nginx_version) do
confine :kernel => [ 'Linux' , 'SunOS' , 'FreeBSD' ]
Copy link
Contributor

Choose a reason for hiding this comment

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

in theory, nginx can run on Windows: http://nginx.org/en/download.html

@danzilio
Copy link
Member

Given the operating system support listed in https://github.com/jfryman/puppet-nginx/blob/master/metadata.json#L25-L59, this seems like a sane approach to me!

@3flex
Copy link
Contributor

3flex commented Jun 23, 2016

I'd rather have special behavior for Windows than white list individual *nix kernels, since some will inevitably be missed.

Can you please try the following on your Windows box? If you can also check the fact on any *nix boxes to make sure it still works that would be great. I don't have access to either at the moment.

I'm not sure if the Windows fact will be ignored because it returns nil... the docs say "If that resolution doesn’t return a value, Facter moves on to the next resolution" but I'm not sure what "doesn't return a value" means for nil. Assuming it stops processing on Windows once the first one returns nil we should be covered.

Facter.add(:nginx_version) do
  confine :kernel => 'Windows'
  setcode do
    return nil
  end
end

Facter.add(:nginx_version) do
  setcode do
    if Facter::Util::Resolution.which('nginx')
      nginx_version = Facter::Util::Resolution.exec('nginx -v 2>&1')
      %r{^nginx version: nginx\/([\w\.]+)}.match(nginx_version)[1]
    end
  end
end

@ekingme
Copy link
Contributor Author

ekingme commented Jun 23, 2016

I was hopeful, but returning nil continued on to the next resolution.

@danzilio
Copy link
Member

This should work:

Facter.add(:nginx_version) do
  setcode do
    if Facter.value(:kernel) == 'windows'
      nginx_version = nil
    elsif Facter::Util::Resolution.which('nginx')
      nginx_version = Facter::Util::Resolution.exec('nginx -v 2>&1')
      %r{^nginx version: nginx\/([\w\.]+)}.match(nginx_version)[1]
    end
  end
end

@ekingme
Copy link
Contributor Author

ekingme commented Jun 23, 2016

@danzilio that works perfectly. Tested on Windows and CentOS 6.

@3flex
Copy link
Contributor

3flex commented Jun 23, 2016

Edit: Ignore the below, solution was posted above already.


Unfortunate - can you try this for me? If it works please rebase your branch on master since there are some fixes for tests in there, and hopefully the facter test will pass.

Facter.add(:nginx_version) do
  setcode do
    kernel = Facter.value('kernel')
    if kernel != 'windows' && Facter::Util::Resolution.which('nginx')
      nginx_version = Facter::Util::Resolution.exec('nginx -v 2>&1')
      %r{^nginx version: nginx\/([\w\.]+)}.match(nginx_version)[1]
    end
  end
end

@3flex
Copy link
Contributor

3flex commented Jun 23, 2016

@danzilio beat me to it! I'd drafted my response but hadn't sent it.

@ekingme please rebase and update with either @danzilio or my code so we can run the test we have for that fact.

@ekingme
Copy link
Contributor Author

ekingme commented Jun 23, 2016

It did a combination of both your changes. I've tested on Windows and CentOS 6, with and without Nginx installed. It's working for me.

I pushed the update to this patch.

Facter.add(:nginx_version) do
  setcode do
    if Facter.value('kernel') != 'windows' && Facter::Util::Resolution.which('nginx')
      nginx_version = Facter::Util::Resolution.exec('nginx -v 2>&1')
      %r{^nginx version: nginx\/([\w\.]+)}.match(nginx_version)[1]
    end
  end
end

@3flex
Copy link
Contributor

3flex commented Jun 23, 2016

One last request: can you please squash to a single commit? Once done I'll merge right away.

Thank you!

@ekingme
Copy link
Contributor Author

ekingme commented Jun 23, 2016

@3flex Done. Thanks!

@3flex 3flex merged commit 9f08550 into voxpupuli:master Jun 23, 2016
slm0n87 pushed a commit to slm0n87/puppet-nginx that referenced this pull request Mar 7, 2019
cegeka-jenkins pushed a commit to cegeka/puppet-nginx that referenced this pull request Sep 13, 2019
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.

4 participants