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

Refs #33760 - Add reports proxy plugin #707

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

ofedoren
Copy link
Member

@ofedoren ofedoren commented Oct 21, 2021

I've just noticed https://projects.theforeman.org/issues/33704...

  • Update based on the issue

Copy link
Member Author

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Actually I need some help to write this properly...

Comment on lines 29 to 50
file_line { "set report type in proxy ansible.cfg":
ensure => present,
path => "${foreman_proxy::config_dir}/ansible.cfg",
line => "report_type = proxy",
after => "^[callback_foreman]"
} ->
file_line { "set proxy url in proxy ansible.cfg":
ensure => present,
path => "${foreman_proxy::config_dir}/ansible.cfg",
line => "proxy_url = ${foreman_proxy::real_registered_proxy_url}",
after => "^[callback_foreman]"
}
Copy link
Member Author

Choose a reason for hiding this comment

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

@lzap, do we want the changes like report_type = proxy to be in the proxy's ansible.cfg? Or we want to change /etc/ansible/ansible.cfg? Or even make this a variable?

@ekohl, how do I write a check in Puppet to append some lines if the file exists? In this case I guess we need to rely on preconfigured ansible.cfg, since a user must have working ansible setup to be able to send/receive reports...

Copy link
Member

Choose a reason for hiding this comment

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

The plan is to add support into installer for changing Ansible configuration but leaving the default on the old setting. Then for 3.2 we want to make it the default and remove core feature leaving the plugin as the only way for reporting.


foreman_proxy::plugin::module { 'host_reports':
enabled => $enabled,
# feature => 'HostReports',
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if we need to introduce a new feature. Please, let me know, so I can send a PR to foreman_host_reports.

Copy link
Member

Choose a reason for hiding this comment

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

I think that would be wise. You can use that in permission checks on API endpoints. Is your current API permission check just "it needs to be any Smart Proxy"?

Additionally, setting feature here means the installer verifies that the Foreman recognizes the feature. That means the foreman_host_reports plugin is installed. If it isn't, there's effectively a mismatch. This mechanism helps to detect that mismatch.

Copy link
Member

@lzap lzap Oct 22, 2021

Choose a reason for hiding this comment

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

Good point, unfortunately our plugin had underscore in the name: host_reports and our feature framework only exposes plugin names. Historically, we only have one-word features, even plugins like remote_execution_ssh use plugin name ssh.

I considered creating a framework to set different feature names in smart proxy, but our endpoint appear to export plugin names directly. Also any change in Foreman feature mapping have potential to break existing plugins (treating underscores differently). Therefore, I renamed the smart proxy plugin name to simply reports (in the initializer) so the feature name is now just Reports in Foreman. This maps cleanly and follows what we have been historically doing.

@ofedoren since it was the free Friday, I pushed the changed directly into repos and made new releases, if you don't mind. :-) I do not want to waste time, we need installer changes for RC1.

Copy link
Member

Choose a reason for hiding this comment

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

Just to explain the previous comment better: host_reports feature from Proxy does map to Host_Reports feature in Foreman which I find way to long and weird. We might even merge Host Reports plugin into core in the future and entitle the pages just "Reports" or "Configuration Reports" so this is much better for the future. And shorter.

])
end

it 'should configure ansible.cfg' do
Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this will fail since it needs a file to exist.

Copy link
Member

Choose a reason for hiding this comment

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

That's configured here:

file {"${foreman_proxy::config_dir}/ansible.cfg":
ensure => file,
content => template('foreman_proxy/plugin/ansible.cfg.erb'),
owner => 'root',
group => $foreman_proxy::user,
mode => '0640',
}

Why do you expect it to configure it as part of this plugin?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, we don't want to fully configure this file, we just need to add two entries: report_type and proxy_url to actually enable redirection of the reports.

file_line { "set proxy url in proxy ansible.cfg":
ensure => present,
path => "${foreman_proxy::config_dir}/ansible.cfg",
line => "proxy_url = ${foreman_proxy::real_registered_proxy_url}",
Copy link
Member Author

Choose a reason for hiding this comment

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

I use here the default/current proxy URL, but I'm open to a better suggestion...

file_line { "set report type in proxy ansible.cfg":
ensure => present,
path => "${foreman_proxy::config_dir}/ansible.cfg",
line => "report_type = proxy",
Copy link
Member Author

@ofedoren ofedoren Oct 21, 2021

Choose a reason for hiding this comment

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

If users install this plugin, I guess they need to be aware that it will work only with this setting in ansible.cfg, thus switching the method automatically.

@ofedoren ofedoren force-pushed the add-host-reports branch 3 times, most recently from c997cbb to d0cee78 Compare October 21, 2021 11:29
@ofedoren ofedoren changed the title Add host_reports proxy plugin Refs #33760 - Add host_reports proxy plugin Oct 21, 2021
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Do you want me close @lzap's issue as a duplicate or will you still use it?

#
# === Parameters:
#
# $proxy_name:: Proxy hostname to appear in reports JSON
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be an advanced parameter? I wonder in which case we actually do want this to be different than the registered name.

For context, the "standard" parameters section is shown with foreman-installer --help and advanced parameters are only shown with foreman-installer --full-help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have strong opinion here, but I think it's safer even for the user to not change that unless they know what they are doing. But in that case it's easy to change in the config itself.

class foreman_proxy::plugin::host_reports (
Optional[String] $proxy_name = undef,
Stdlib::Absolutepath $spool_dir = '/var/lib/foreman-proxy/host_reports',
Optional[String] $keep_reports = false,
Copy link
Member

Choose a reason for hiding this comment

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

This looks more like a Boolean

Stdlib::Absolutepath $spool_dir = '/var/lib/foreman-proxy/host_reports',
Optional[String] $keep_reports = false,
# No reports are redirected by default
Optional[String] $report_type = 'foreman',
Copy link
Member

Choose a reason for hiding this comment

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

If there's a default, it's not Optional. In Puppet the type Optional[String] is equivalent to Variant[Undef, String] but you can't get back to undef if there's a default. If there are just 2 values possible (as the documentation suggests) you can also use an even stricter type:

Suggested change
Optional[String] $report_type = 'foreman',
Enum['foreman', 'proxy'] $report_type = 'foreman',

])
end

it 'should configure ansible.cfg' do
Copy link
Member

Choose a reason for hiding this comment

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

That's configured here:

file {"${foreman_proxy::config_dir}/ansible.cfg":
ensure => file,
content => template('foreman_proxy/plugin/ansible.cfg.erb'),
owner => 'root',
group => $foreman_proxy::user,
mode => '0640',
}

Why do you expect it to configure it as part of this plugin?

:enabled: <%= @module_enabled %>

# Proxy hostname to appear in reports JSON
:reported_proxy_hostname: <%= scope.lookupvar('::foreman_proxy::plugin::host_reports::reported_proxy_hostname') %>
Copy link
Member

Choose a reason for hiding this comment

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

It's no longer needed to use ::foreman_proxy. That was a thing for Puppet 3 and Puppet 4 to behave in the same way but thankfully we've dropped Puppet 3 a long time ago.

Suggested change
:reported_proxy_hostname: <%= scope.lookupvar('::foreman_proxy::plugin::host_reports::reported_proxy_hostname') %>
:reported_proxy_hostname: <%= scope.lookupvar('foreman_proxy::plugin::host_reports::reported_proxy_hostname') %>

# a regular basis (e.g. via cronjob).
:keep_reports: <%= scope.lookupvar('::foreman_proxy::plugin::host_reports::keep_reports') %>

# Development settings (do not use)
Copy link
Member

Choose a reason for hiding this comment

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

If these are "do not use", should we remove these lines?

Copy link
Member Author

@ofedoren ofedoren left a comment

Choose a reason for hiding this comment

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

Thanks, @ekohl, updated.

Do you want me close @lzap's issue as a duplicate or will you still use it?

Sure, I guess we don't need that.

Regarding #707 (comment), I still need to append those changes only if the file exists since Foreman can be used with Puppet only.

#
# === Parameters:
#
# $proxy_name:: Proxy hostname to appear in reports JSON
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't have strong opinion here, but I think it's safer even for the user to not change that unless they know what they are doing. But in that case it's easy to change in the config itself.

Comment on lines 39 to 50
file_line { 'set report type in proxy ansible.cfg':
ensure => present,
path => "${foreman_proxy::config_dir}/ansible.cfg",
line => "report_type = ${report_type}",
after => '^[callback_foreman]',
}
-> file_line { 'set proxy url in proxy ansible.cfg':
ensure => present,
path => "${foreman_proxy::config_dir}/ansible.cfg",
line => "proxy_url = ${foreman_proxy::real_registered_proxy_url}",
after => '^[callback_foreman]',
}
Copy link
Member

Choose a reason for hiding this comment

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

You can't do this reliably since the Ansible plugin already manages the file. To have that as leading and modify the template:
https://github.com/theforeman/puppet-foreman_proxy/blob/master/templates/plugin/ansible.cfg.erb

It may mean that you need to introduce additional parameters in ansible.pp

Comment on lines 10 to 12
proxy_url = <%= @proxy_url %>
report_type = <%= @report_type %>
url = <%= @foreman_url %>
Copy link
Member

Choose a reason for hiding this comment

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

Why does the callback have a url and proxy_url? Is that because facts are still sent to Foreman itself unconditionally?

Copy link
Member Author

@ofedoren ofedoren Oct 21, 2021

Choose a reason for hiding this comment

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

Exactly. Also, AFAIU the proxy can have a different url than the server, so it's safer to configure it separately.

But @lzap can say more about that.

Copy link
Member

Choose a reason for hiding this comment

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

Not just can, its URL is always different since it's never on the same port. So yes, this makes sense.

# Proxy hostname to appear in reports JSON
:reported_proxy_hostname: <%= scope.lookupvar('foreman_proxy::plugin::host_reports::reported_proxy_hostname') %>

# Print intput and output to the debug level
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
# Print intput and output to the debug level
# Print input and output to the debug level


describe 'with default settings' do
it { should contain_foreman_proxy__plugin__module('host_reports') }
it 'host_reports.yml should contain the correct configuration' do
Copy link
Member

Choose a reason for hiding this comment

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

I think this reads a bit more natural:

Suggested change
it 'host_reports.yml should contain the correct configuration' do
it 'should contain the correct configuration in host_reports.yml' do

#
# === Parameters:
#
# $spool_dir:: Spool directory with processed reports
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this also more of an advanced parameter that most users wouldn't change?

@@ -50,11 +53,13 @@
String $callback = $foreman_proxy::plugin::ansible::params::callback,
String $runner_package_name = $foreman_proxy::plugin::ansible::params::runner_package_name,
Array[Stdlib::Absolutepath] $collections_paths = $foreman_proxy::plugin::ansible::params::collections_paths,
Enum['foreman', 'proxy'] $report_type = $foreman_proxy::plugin::ansible::params::report_type,
Copy link
Member

Choose a reason for hiding this comment

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

Just thinking out loud: should proxy type automatically enable the host reporting feature? The only downside is that it wouldn't get disabled again if the users switches it to foreman again. I'd be OK with adding a line to the parameter documentation that tells the user to enable the host_reports plugin (both the Foreman and Proxy parts)

Copy link
Member Author

@ofedoren ofedoren Oct 21, 2021

Choose a reason for hiding this comment

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

Not sure I follow what you mean... I see there are two ways for "enabling":

  1. Install host_reports*; enable proxy in config.
  2. Set report_type to proxy.

The whole feature (for Ansible) will work only if both ways are applied. For Puppet the first one only will do (but with additional configuration of puppet client/server).

UPD: Also, for now switching proxy to foreman should disable forwarding and should "return things they were". This wouldn't be the case in the future though, since we're going to remove old API and stuff.

Copy link
Member

Choose a reason for hiding this comment

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

The whole feature (for Ansible) will work only if both ways are applied. For Puppet the first one only will do (but with additional configuration of puppet client/server).

Right, so I'm wondering if you set this value to proxy, should we do something about warning the user they'll have an incompatible setup somehow. But as I said: I'm fine with adding a line to the parameter documentation in this class that's something like "If set to proxy, the host_reports plugin must be enabled".

Copy link
Member Author

@ofedoren ofedoren Oct 21, 2021

Choose a reason for hiding this comment

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

Oh, right, will do. Done.


foreman_proxy::plugin::module { 'host_reports':
enabled => $enabled,
feature => 'HostReports',
Copy link
Member Author

Choose a reason for hiding this comment

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

Returned this since it's going to be added in theforeman/foreman_host_reports#10. Probably, we need to extract that to not block this PR.

@ofedoren ofedoren force-pushed the add-host-reports branch 2 times, most recently from b9674aa to 1dd2f24 Compare October 22, 2021 12:55
@ehelms ehelms mentioned this pull request Oct 24, 2021
7 tasks
describe 'with default settings' do
it { should contain_foreman_proxy__plugin__module('host_reports') }
it 'should contain the correct configuration in host_reports.yml' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/host_reports.yml', [
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this was renamed in 0.0.4 to just reports.yml. In theforeman/foreman-packaging#7194 (review) I suggested to rename everything to be consistent. Perhaps we should first have that discussion and then decide on what we do here.

@ofedoren ofedoren changed the title Refs #33760 - Add host_reports proxy plugin Refs #33760 - Add reports proxy plugin Oct 26, 2021
@ofedoren
Copy link
Member Author

Updated to match the renaming.

@lzap
Copy link
Member

lzap commented Nov 1, 2021

Packaging PR has been merged: theforeman/foreman-packaging#7194

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Thanks!

@ekohl ekohl merged commit e07f581 into theforeman:master Nov 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants