diff --git a/.fixtures.yml b/.fixtures.yml index 20abd2b..e9c3f5e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,7 +2,7 @@ fixtures: repositories: stdlib: repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: 'v8.1.0' + ref: 'v9.0.0' concat: repo: 'https://github.com/puppetlabs/puppetlabs-concat.git' ref: 'v7.1.1' diff --git a/data/os/windows.yaml b/data/os/windows.yaml index fd8c7df..8555e5f 100644 --- a/data/os/windows.yaml +++ b/data/os/windows.yaml @@ -8,3 +8,8 @@ facter::facts_file_owner: 'NT AUTHORITY\SYSTEM' facter::facts_file_group: 'NT AUTHORITY\SYSTEM' facter::facts_file_mode: null facter::ensure_facter_symlink: false +facter::facter_conf_dir: 'C:\ProgramData\PuppetLabs\facter\etc' +facter::facter_conf_dir_owner: 'NT AUTHORITY\SYSTEM' +facter::facter_conf_dir_group: 'NT AUTHORITY\SYSTEM' +facter::facter_conf_owner: 'NT AUTHORITY\SYSTEM' +facter::facter_conf_group: 'NT AUTHORITY\SYSTEM' diff --git a/manifests/init.pp b/manifests/init.pp index 14b5bfd..53967d2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -66,6 +66,15 @@ String[1] $facts_file_owner = 'root', String[1] $facts_file_group = 'root', Optional[Stdlib::Filemode] $facts_file_mode = '0644', + Stdlib::Absolutepath $facter_conf_dir = '/etc/puppetlabs/facter', + String[1] $facter_conf_dir_owner = 'root', + String[1] $facter_conf_dir_group = 'root', + Stdlib::Filemode $facter_conf_dir_mode = '0755', + String[1] $facter_conf_name = 'facter.conf', + String[1] $facter_conf_owner = 'root', + String[1] $facter_conf_group = 'root', + Stdlib::Filemode $facter_conf_mode = '0644', + Facter::Conf $facter_conf = {}, ) { if $facts['os']['family'] == 'windows' { $facts_file_path = "${facts_d_dir}\\${facts_file}" @@ -145,4 +154,35 @@ * => $v, } } + + if $facts['os']['family'] == 'windows' { + exec { "mkdir_p-${facter_conf_dir}": + command => "cmd /c mkdir ${facter_conf_dir}", + creates => $facter_conf_dir, + path => $facts['path'], + } + } else { + exec { "mkdir_p-${facter_conf_dir}": + command => "mkdir -p ${facter_conf_dir}", + creates => $facter_conf_dir, + path => '/bin:/usr/bin', + } + } + file { $facter_conf_dir: + ensure => 'directory', + owner => $facter_conf_dir_owner, + group => $facter_conf_dir_group, + mode => $facter_conf_dir_mode, + require => Exec["mkdir_p-${facter_conf_dir}"], + } + if ! empty($facter_conf) { + $facter_conf_json = stdlib::to_json_pretty($facter_conf) + file { "${facter_conf_dir}/${facter_conf_name}": + ensure => 'file', + owner => $facter_conf_owner, + group => $facter_conf_group, + mode => $facter_conf_mode, + content => "# File managed by Puppet, do not edit\n${facter_conf_json}", + } + } } diff --git a/metadata.json b/metadata.json index b94d17f..aad70af 100644 --- a/metadata.json +++ b/metadata.json @@ -10,7 +10,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 8.1.0 < 9.0.0" + "version_requirement": ">= 9.0.0 < 10.0.0" }, { "name": "puppetlabs/concat", diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 05bf505..c402c23 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -60,6 +60,25 @@ 'path' => '/bin:/usr/bin', }) } + + it { + should contain_exec('mkdir_p-/etc/puppetlabs/facter').with({ + 'command' => 'mkdir -p /etc/puppetlabs/facter', + 'unless' => 'test -d /etc/puppetlabs/facter', + }) + } + + it { + should contain_file('/etc/puppetlabs/facter').with({ + 'ensure' => 'directory', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755', + 'require' => 'Exec[mkdir_p-/etc/puppetlabs/facter]', + }) + } + + it { should_not contain_file('/etc/puppetlabs/facter/facter.conf') } end describe 'with purge_facts_d' do @@ -324,7 +343,10 @@ 'fact' => { 'value' => 'value', }, - } + }, + :facter_conf => { + 'global' => { 'external-dir' => ['/foo'] }, + }, } end @@ -376,6 +398,25 @@ 'content' => 'fact=value', }) } + + it { + should contain_file('/etc/puppetlabs/facter/facter.conf').with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'content' => '# File managed by Puppet, do not edit +{ + "global": { + "external-dir": [ + "/foo" + ] + } +} +' + }) + } + end describe 'variable type and content validations' do diff --git a/types/conf.pp b/types/conf.pp new file mode 100644 index 0000000..9139fcd --- /dev/null +++ b/types/conf.pp @@ -0,0 +1,19 @@ +# +type Facter::Conf = Struct[{'facts' => Optional[Struct[{ + 'blocklist' => Optional[Array[String]], + 'ttls' => Optional[Array[Hash]] + }]], + 'global' => Optional[Struct[{ + 'external-dir' => Optional[Array[Stdlib::Absolutepath]], + 'custom-dir' => Optional[Array[Stdlib::Absolutepath]], + 'no-external-facts' => Optional[Boolean], + 'no-custom-facts' => Optional[Boolean], + 'no-ruby' => Optional[Boolean] + }]], + 'cli' => Optional[Struct[{ + 'debug' => Optional[Boolean], + 'trace' => Optional[Boolean], + 'verbose' => Optional[Boolean], + 'log-level' => Optional[Boolean] + }]] + }] \ No newline at end of file