Skip to content
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

Add service to publish facts to foreman #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
34 changes: 34 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a $enc parameter which you can use. Perhaps fail() if both are true?

Technically you could look at $enc_upload_facts but then you don't have a guarantee that the facts are uploaded before the ENC is calculated. Uploading facts will create a host entry when it doesn't exist, so I wouldn't do that.

# @param manage_fact_watcher_dependencies
# Install the missing dependencies for fact_watchter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Install the missing dependencies for fact_watchter
# Install the missing dependencies for fact_watcher

class puppetserver_foreman (
Stdlib::HTTPUrl $foreman_url = $puppetserver_foreman::params::foreman_url,
Boolean $enc = true,
Expand All @@ -58,6 +62,8 @@
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 = $puppetserver_foreman::params::fact_watcher_service,
Boolean $manage_fact_watcher_dependencies = true,
) inherits puppetserver_foreman::params {
case $facts['os']['family'] {
'Debian': { $json_package = 'ruby-json' }
Expand Down Expand Up @@ -126,5 +132,33 @@
group => $puppet_group,
mode => '0750',
}
if $manage_fact_watcher_dependencies {
$ensure = if $fact_watcher_service {
'installed'
} else {
'absent'
}
package { 'ruby-inotify':
ensure => 'installed',
provider => 'puppet_gem',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike using the puppet_gem provider (or really, gem on production servers). If you upgrade your Puppet AIO it may break the native extensions and you don't know what you're pulling in.

before => Systemd::Unit_file['fact_watcher.service'],
}
}
systemd::manage_unit { 'fact_watcher.service':
enable => $fact_watcher_service,
active => $fact_watcher_service,
unit_entry => {
'Description' => 'Publish facts to Foreman',
},
service_entry => {
'Type' => 'simple',
'Environment' => "PATH=/opt/puppetlabs/puppet/bin:${facts['path']}",
'User' => $puppet_user,
'ExecStart' => "${puppet_etcdir}/node.rb --watch-facts --push-facts-parallel",
Comment on lines +155 to +157
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to enforce the AIO Ruby (and I really dislike it), perhaps this is better?

Suggested change
'Environment' => "PATH=/opt/puppetlabs/puppet/bin:${facts['path']}",
'User' => $puppet_user,
'ExecStart' => "${puppet_etcdir}/node.rb --watch-facts --push-facts-parallel",
'User' => $puppet_user,
'ExecStart' => "/opt/puppetlabs/puppet/bin/ruby ${puppet_etcdir}/node.rb --watch-facts --push-facts-parallel",

},
install_entry => {
'WantedBy' => 'multi-user.target',
},
}
}
}
9 changes: 6 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@

# PE uses a different user/group compared to open source puppet
# the is_pe fact exists in PE and in stdlib. It can be true/false/undef (undef means open source)
$puppet_user = $facts['is_pe'] ? {
true => 'pe-puppet',
default => 'puppet'
if $facts['is_pe'] {
$puppet_user = 'pe-puppet'
$fact_watcher_service = true
} else {
$puppet_user = 'puppet'
$fact_watcher_service = false
}
}
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system RedHat 6

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system RedHat 7

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 6

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 7

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system CentOS 8

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system Debian 9

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system Debian 10

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system Ubuntu 16.04

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system Ubuntu 18.04

Check warning on line 1 in metadata.json

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Skipping EOL operating system FreeBSD 11
"name": "theforeman-puppetserver_foreman",
"version": "4.0.0",
"author": "theforeman",
Expand All @@ -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 @@ -75,12 +75,14 @@
.with_require('Exec[Create Puppet Reports dir]')
end

it 'should set up enc' do

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]

Check failure on line 78 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 should set up enc Failure/Error: should_not contain_systemd__unit_file('fact_watcher.service') expected that the catalogue would not contain Systemd::Unit_file[fact_watcher.service]
should contain_file("#{etc_dir}/node.rb")
.with_mode('0550')
.with_owner('puppet')
.with_group('puppet')
.with_content(%r{foreman\.yaml})

should_not contain_systemd__unit_file('fact_watcher.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
{fact_watcher_service: true}
end
it { is_expected.to contain_systemd__unit_file('fact_watcher.service') }
end
end
end
end
Loading