Conversation
lib/facter/util/confine.rb
Outdated
There was a problem hiding this comment.
You could get rid of the conditional and simply do @block = block. If no block is passed then the block argument will be nil.
There was a problem hiding this comment.
yes, but I still needed it for the others. but I can have them in a unless block_given?
There was a problem hiding this comment.
Ah yes, sorry.
So... I don't yet understand how this change set works. If we discard the fact we're confining to, how does Facter know what value to yield to the block?
There was a problem hiding this comment.
It doesn't yield any value. Either you pass only a block to confine like for example:
confine { File.exist?('/usr/bin/lldpctl') }Or you pass a fact and one or more values that it should match like
confine :manufacturer => /Dell.*/The value it is matched against can however also be a Proc object in which case the fact value is yielded to it, like:
confine :ipaddress => lambda { |addr| IPAddr.new('192.168.0.0/16').include? addr }But the new thing in this pull request compared to Pull #408 is the first variant.
|
CLA Signed by dalen on 2012-07-17 21:00:00 -0700 |
|
I'm trying to use this and I've written a simple fact to try out the new behavior: Facter.add("jeff") do
confine :operatingsystem do |os|
require 'pry'; binding.pry
true
end
setcode do
"Jeff #{rand(1000)}"
end
endIt seems as though the block never gets executed. The confine method in Could you give me an example of how you're using these block based confinements? Unfortunately, I don't think we're going to be able to get this into 1.7.0, sorry... I'll look at cleaning it up in the next hour, but I'm going to have to switch back to working against a deadline task if my refactoring goes beyond that. -Jeff |
|
@dalen it's been a week since this has seen activity, and it looks like this PR needs to be rebased. Do you know what the status of this PR is? |
|
It is just waiting for review the last week. Jeff had some thoughts about how the syntax should be and then I've implemented that. |
Allows a confine to take only a block parameter like:
confine { File.exist? '/bin/foo' }
Or take a fact name and a block:
confine :ipaddress do |addr|
require 'ipaddr'
IPAddr.new('192.168.0.0/16').include? addr
end
This is similar to what Puppet allows in provider confines.
|
summary: Merged into master as b7f75cf. This should be released in Facter 2. Thanks again for the contribution! Please note, I re-wrote the The updated documentation provides specific documentation for each overloaded form of -Jeff |

Allow confine to take a block parameter, like:
Builds on top of pull #408