-
Notifications
You must be signed in to change notification settings - Fork 241
Add facter/openfact configuration support #978
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
Open
jay7x
wants to merge
1
commit into
theforeman:master
Choose a base branch
from
jay7x:facter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # Manage Facter/Openfact configuration | ||
| # @param config_dir | ||
| # Override configuration directory | ||
| # @param config_file | ||
| # Override configuration file name | ||
| # @param config | ||
| # Override configuration | ||
| class puppet::agent::facter ( | ||
| Stdlib::Absolutepath $config_dir = $puppet::facter_config_dir, | ||
| String[1] $config_file = 'facter.conf', | ||
| Puppet::Facter::Config $config = $puppet::facter_config, | ||
| ) { | ||
| $config_text = @("CONFIG") | ||
| # Managed by Puppet | ||
| ${config.stdlib::to_json_pretty()} | ||
| |-CONFIG | ||
|
|
||
| file { $config_dir: | ||
| ensure => 'directory', | ||
| } | ||
|
|
||
| file { "${config_dir}/${config_file}": | ||
| ensure => 'file', | ||
| content => $config_text, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe 'Puppet::Facter::Config::TTL' do | ||
| [ | ||
| 'ns', | ||
| 'nano', | ||
| 'nanos', | ||
| 'nanosecond', | ||
| 'nanoseconds', | ||
| 'us', | ||
| 'micro', | ||
| 'micros', | ||
| 'microsecond', | ||
| 'microseconds', | ||
| 'ms', | ||
| 'mili', | ||
| 'milis', | ||
| 'millisecond', | ||
| 'milliseconds', | ||
| 's', | ||
| 'second', | ||
| 'seconds', | ||
| 'm', | ||
| 'minute', | ||
| 'minutes', | ||
| 'h', | ||
| 'hours', | ||
| 'd', | ||
| 'day', | ||
| 'days', | ||
| ].each do |t| | ||
| it { is_expected.to allow_value("123 #{t}") } | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # @summary Facter configuration type | ||
| type Puppet::Facter::Config = Struct[{ | ||
| Optional['facts'] => Puppet::Facter::Config::Facts, | ||
| Optional['global'] => Puppet::Facter::Config::Global, | ||
| Optional['cli'] => Puppet::Facter::Config::CLI, | ||
| Optional['fact-groups'] => Hash[String[1], Array[String[1]]], | ||
| }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # @summary Facter `cli` configuration type | ||
| # | ||
| # @note All these settings are ignored when called from the Ruby API (by Puppet/OpenVox) | ||
| type Puppet::Facter::Config::CLI = Struct[{ | ||
| Optional['debug'] => Boolean, | ||
| Optional['trace'] => Boolean, | ||
| Optional['verbose'] => Boolean, | ||
| Optional['log-level'] => Enum['none','trace','debug','info','warn','error','fatal'], | ||
| }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # @summary Facter `facts` configuration type | ||
| type Puppet::Facter::Config::Facts = Struct[{ | ||
| Optional['blocklist'] => Array[String[1]], | ||
| Optional['ttls'] => Array[Hash[String[1], Puppet::Facter::Config::TTL]], | ||
| }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # @summary Facter `global` configuration type | ||
| # | ||
| # @note Options below cannot be `true` when using Facter/Openfact with Puppet/OpenVox: | ||
| # * `no-custom-facts` | ||
| # * `no-ruby` | ||
| type Puppet::Facter::Config::Global = Struct[{ | ||
| Optional['external-dir'] => Array[Stdlib::Absolutepath], | ||
| Optional['custom-dir'] => Array[Stdlib::Absolutepath], | ||
| Optional['no-external-facts'] => Boolean, | ||
| Optional['no-custom-facts'] => Boolean[false], # Cannot be true | ||
| Optional['no-ruby'] => Boolean[false], # Cannot be true | ||
| }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # @summary Facter `facts.ttls` ttl value type | ||
| type Puppet::Facter::Config::TTL = Variant[ | ||
| Integer[0], | ||
| # See STRING_TO_SECONDS and ttls_to_seconds() in | ||
| # https://github.com/OpenVoxProject/openfact/blob/main/lib/facter/framework/config/fact_groups.rb | ||
| Pattern[/^\d+( +(ns|nano(s)?|nanosecond(s)?|us|micro(s)?|microsecond(s)?|ms|mili(s)?|millisecond(s)?|s|second(s)?|m|minute(s)?|h|hour(s)?|d|day(s)?))?$/] | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As
$puppet::facter_configcannot beundefand is represented by Hash, so this should work (at least I'm always using it instead ofemtpy()which is stdlib function).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example should be better:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change if
empty()is preferred from a style perspective though :)