Skip to content

Commit

Permalink
Add service to publish facts to foreman
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Oct 25, 2024
1 parent 9b0ac1e commit 34daffb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fixtures:
repositories:
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
systemd: 'https://github.com/voxpupuli/puppet-systemd'
12 changes: 11 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
# The directory used to install the report processor to
# @param use_client_tls_certs
# Enable client TLS authentication to foreman
# @param watch_for_facts_and_publish_them
# Sets up a simple systemd unit that watches for new fact files and publishes them to foreman. Not required when foreman is the ENC
class puppetserver_foreman (
Stdlib::HTTPUrl $foreman_url = $puppetserver_foreman::params::foreman_url,
Boolean $enc = true,
Expand All @@ -58,6 +60,7 @@
Variant[Enum[''], Stdlib::Absolutepath] $ssl_cert = $puppetserver_foreman::params::client_ssl_cert,
Variant[Enum[''], Stdlib::Absolutepath] $ssl_key = $puppetserver_foreman::params::client_ssl_key,
Boolean $use_client_tls_certs = true,
Boolean $watch_for_facts_and_publish_them = false,
) inherits puppetserver_foreman::params {
case $facts['os']['family'] {
'Debian': { $json_package = 'ruby-json' }
Expand Down Expand Up @@ -93,7 +96,7 @@
file { "${puppet_etcdir}/node.rb":
ensure => file,
content => file("${module_name}/enc.rb"),
mode => '0550',
mode => '0755',
owner => $puppet_user,
group => $puppet_group,
}
Expand Down Expand Up @@ -126,5 +129,12 @@
group => $puppet_group,
mode => '0750',
}
if $watch_for_facts_and_publish_them {
systemd::unit_file { 'facts.service':
enable => true,
active => true,
content => epp('puppetserver_foreman/facts.service.epp', { 'user' => $puppet_user }),
}
}
}
}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
{
"name": "puppetlabs/stdlib",
"version_requirement": ">= 9.0.0 < 10.0.0"
},
{
"name": "puppet/systemd",
"version_requirement": ">= 7.1.0 < 8.0.0"
}
],
"requirements": [
Expand Down
8 changes: 8 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
.with_owner('puppet')
.with_group('puppet')
.with_content(%r{foreman\.yaml})

should.not contain_systemd__unit_file('facts.service')
end

it 'should set up directories for the ENC' do
Expand Down Expand Up @@ -168,6 +170,12 @@

it { should contain_class('puppetserver_foreman').with_foreman_url('https://hiera-foreman.example.com') }
end
describe 'setup service to pubish facts' do
let :params do
{watch_for_facts_and_publish_them: true}
end
it { is_expected.to contain_systemd__unit_file('facts.service') }

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on centos-6-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az1456-421.m124l1r4sqdexegkwpsehxmp0h.phxx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on redhat-6-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az1456-421.m124l1r4sqdexegkwpsehxmp0h.phxx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on scientific-6-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az1456-421.m124l1r4sqdexegkwpsehxmp0h.phxx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on almalinux-8-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az1456-421.m124l1r4sqdexegkwpsehxmp0h.phxx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on almalinux-9-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az1456-421.m124l1r4sqdexegkwpsehxmp0h.phxx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on freebsd-12-amd64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az525-994.gmvlfiqlijledoifuxan3ve3oh.dx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on almalinux-8-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az525-994.gmvlfiqlijledoifuxan3ve3oh.dx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on ubuntu-22.04-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az525-994.gmvlfiqlijledoifuxan3ve3oh.dx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on ubuntu-16.04-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az525-994.gmvlfiqlijledoifuxan3ve3oh.dx.internal.cloudapp.net

Check failure on line 177 in spec/classes/init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on ubuntu-18.04-x86_64 setup service to pubish facts is expected to contain Systemd::Unit_file[facts.service] Failure/Error: it { is_expected.to contain_systemd__unit_file('facts.service') } Puppet::PreformattedError: Evaluation Error: Error while evaluating a Function Call, Could not find template 'puppetserver_foreman/facts.service.epp' (file: /home/runner/work/puppet-puppetserver_foreman/puppet-puppetserver_foreman/spec/fixtures/modules/puppetserver_foreman/manifests/init.pp, line: 136, column: 20) on node fv-az525-994.gmvlfiqlijledoifuxan3ve3oh.dx.internal.cloudapp.net
end
end
end
end
12 changes: 12 additions & 0 deletions templates/facts.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%- | String[1] $user | -%>
# THIS FILE IS MANAGED BY PUPPET
[Unit]
Description=publish facts to foreman

[Service]
Type=simple
User=<%= $user %>
ExecStart=/etc/puppetlabs/puppet/node.rb --watch-facts

[Install]
WantedBy=multi-user.target

0 comments on commit 34daffb

Please sign in to comment.