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 bb208a1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
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'
14 changes: 14 additions & 0 deletions 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 fact_watcher_service
# 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 $fact_watcher_service = false,
) inherits puppetserver_foreman::params {
case $facts['os']['family'] {
'Debian': { $json_package = 'ruby-json' }
Expand Down Expand Up @@ -126,5 +129,16 @@
group => $puppet_group,
mode => '0750',
}
if $fact_watcher_service {
package { 'ruby-inotify':
ensure => 'installed',
provider => 'puppet_gem',
}
-> systemd::unit_file { 'fact_watcher.service':
enable => true,
active => true,
content => epp('puppetserver_foreman/fact_watcher.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
7 changes: 7 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
.with_group('puppet')
.with_content(%r{foreman\.yaml})
end
it { is.expected.not_to contain_systemd__unit_file('facts.service') }

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnCentos6X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnRedhat6X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnScientific6X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnAlmalinux8X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnAlmalinux9X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

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

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on archlinux-rolling-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnArchlinuxRollingX8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

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

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on centos-7-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnCentos7X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

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

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on centos-8-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnCentos8X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

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

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on debian-10-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnDebian10X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

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

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

puppetserver_foreman on debian-11-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnDebian11X8664::WithoutCustomParameters "example at ./spec/classes/init_spec.rb:85">

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnFreebsd12Amd64::WithoutCustomParameters:0x0000555f223b00c0>

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnAlmalinux8X8664::WithoutCustomParameters:0x0000555f1c3574f8>

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnUbuntu2204X8664::WithoutCustomParameters:0x0000555f22055e20>

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnUbuntu1604X8664::WithoutCustomParameters:0x0000555f1c234710>

Check failure on line 85 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 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnUbuntu1804X8664::WithoutCustomParameters:0x0000555f20143be0>

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

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on redhat-7-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnRedhat7X8664::WithoutCustomParameters:0x0000555f1b3653b0>

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

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on debian-11-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnDebian11X8664::WithoutCustomParameters:0x0000555f1e048698>

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

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on debian-10-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnDebian10X8664::WithoutCustomParameters:0x0000555f2222bab0>

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

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on ubuntu-20.04-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnUbuntu2004X8664::WithoutCustomParameters:0x0000555f203000f0>

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

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

puppetserver_foreman on debian-9-x86_64 without custom parameters Failure/Error: it { is.expected.not_to contain_systemd__unit_file('facts.service') } NameError: undefined local variable or method `is' for #<RSpec::ExampleGroups::PuppetserverForeman::OnDebian9X8664::WithoutCustomParameters:0x0000555f205dc260>

it 'should set up directories for the ENC' do
should contain_file("#{var_dir}/yaml")
Expand Down Expand Up @@ -168,6 +169,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
{fact_watcher_service: true}
end
it { is_expected.to contain_systemd__unit_file('fact_watcher.service') }
end
end
end
end
13 changes: 13 additions & 0 deletions templates/fact_watcher.service.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%- | String[1] $user | -%>
# THIS FILE IS MANAGED BY PUPPET
[Unit]
Description=publish facts to foreman

[Service]
Type=simple
Environment=PATH=/opt/puppetlabs/puppet/bin:<%= $facts['path'] %>
User=<%= $user %>
ExecStart=/etc/puppetlabs/puppet/node.rb --watch-facts --push-facts

[Install]
WantedBy=multi-user.target

0 comments on commit bb208a1

Please sign in to comment.