diff --git a/.fixtures.yml b/.fixtures.yml index 4f2c1f9..6f7d482 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,3 +1,4 @@ fixtures: repositories: stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib' + systemd: 'https://github.com/voxpupuli/puppet-systemd' diff --git a/manifests/init.pp b/manifests/init.pp index e64d789..f3c4864 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, @@ -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' } @@ -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 }), + } + } } } diff --git a/metadata.json b/metadata.json index 93221c0..a774af3 100644 --- a/metadata.json +++ b/metadata.json @@ -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": [ diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 2b1c25f..ba98aef 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -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 @@ -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') } + end end end end diff --git a/templates/facts.service.epp b/templates/facts.service.epp new file mode 100644 index 0000000..92dd69c --- /dev/null +++ b/templates/facts.service.epp @@ -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