Hello everyone,
As a part of staypuft project (openstack installer based on foreman in form of
foreman plugin) we created a script that setup foreman instance to be able to
provision other machines easily [1]. It has a lot of hardcoded values since
it's for livecd specific purpose. I'd like to improve that and built it into
foreman-installer. The result should be installer which setups foreman ready
for provisioning machines and which will be usable by most of users (at least
for testing) without any further actions. I'd also like it to be customizable
and completely optional for advanced users.
Staypuft may require other seed data or relations (see below) than vanilla
foreman so some parts should be optional and customizable from outside (either
puppet module or just by adding some files to vanilla foreman-installer, not
editing existing ones)
I think we basically need two new features in installer (kafo):
- As a developer I want to specify parameter relations and change actions
- As a developer I want to specify seed data for installed foreman instance
Let's focus on 1. at first. I'd like to be able to setup provisioning just by
specifying NIC. Most of values can be determined based on that and output of
Facter. So e.g. we can setup subnet because we can guess CIDR, dhcp range,
gateway by Facter information about particular NIC. However this mean that one
parameter must be able to set value of other parameters dynamically so when
user selects eth0 he gets different values than for eth1. I'd like to add
support for so called parameter callbacks so you could say "execute this block
when param1.value changes".
For the staypuft effort these parameter callbacks would be defined in Kafo hooks
[2]. Kafo currently support :pre and :post hooks. We just need to extend it so
other installers can register their own hooks (in this case before parameter
values are parsed and set) easily. I think creating directory for hooks
definitions could do the trick, so anyone could add his own kafo hook. This
would also cleanup bin/installer script and could prevent duplication between
foreman and katello installers because existing hooks (e.g. --foreman-reset-
db) would be extracted.
So in this hook we'd define paramater hooks like this (DSL is just an example)
KafoConfigure.register_init do |kafo|
set to static value, not too useful here but may be somewhere else
kafo.param('staypuft/interface').changes('foreman-proxy/dhcp/interface',
'eth0')
set dynamically whenever staypuft/installer value changes
kafo.param('staypuft/interface').changes('foreman-proxy/dhcp/range') {|kafo|
kafo.param('foreman-proxy/dhcp/range').value = …
}
end
Note that we have to add some cycle detection mechanism so when we try to
change some param we don't change it's value again.
This seems very straightforward to me and it should allow us to reuse this to
create even better user experience with other parameters, so one parameter can
modify/set other but user can still go and change those if he needs.
To the second feature. What the staypuft script does is that it uses
foreman_api to set a lot of relations and some default objects. It's basically
seeding but important difference is that seed does not have access to installer
answers. Well it could have been read from answers file if user hadn't deleted
it, but I think it make more sense to leverage installer for this since it's
the same process running under root (we may need to read some system data,
maybe even not present in answers file). Again I'd like to use kafo hooks here.
We can use post hook that will be triggered just after puppet run is done,
which means foreman is up and running (and already seeded by seed.rb).
Later (not needed for staypuft at all) we could add support to define parameter
callbacks into rdoc so they are on the same place with rest of puppet class
'configuration', but it depends on their complexity.
Any feedback would be appreciated. Please let me know if any parts needs more
elaborating.
[1]https://github.com/radez/foreman-live/blob/master/setup_provisioning.rb
[2]https://github.com/theforeman/kafo#hooks