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
Make bootstrap.py compatible with Puppet 4 #230
Conversation
Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
bootstrap.py
Outdated
@@ -383,7 +383,10 @@ def install_puppet_agent(): | |||
call_yum("install", "puppet") | |||
enable_service("puppet") | |||
|
|||
puppet_conf = open('/etc/puppet/puppet.conf', 'wb') | |||
if os.path.isfile('/etc/puppet/puppet.conf'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we turn that around and handle /etc/puppetlabs
as the special case? feels slightly "cleaner" to me
bootstrap.py
Outdated
@@ -407,7 +410,10 @@ def install_puppet_agent(): | |||
print_generic("Running Puppet in noop mode to generate SSL certs") | |||
print_generic("Visit the UI and approve this certificate via Infrastructure->Capsules") | |||
print_generic("if auto-signing is disabled") | |||
exec_failexit("/usr/bin/puppet agent --test --noop --tags no_such_tag --waitforcert 10") | |||
if os.path.isfile('/usr/bin/puppet'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we turn that around and test for /opt/puppetlabs/puppet/bin/puppet
? and in the else case, run puppet without a path at all, so the shell can find it even in another folder?
The changes add functionality for detecting the installed version of puppet and configures the puppet accordingly. Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
bootstrap.py
Outdated
return executable_path | ||
|
||
|
||
def get_puppet_version(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd still prefer using the RPMdb like this:
def get_puppet_version():
ts = rpm.TransactionSet()
for name in ['puppet', 'puppet-agent']:
mi = ts.dbMatch('name', name)
for h in mi:
puppet_version = int(h['version'].split('.')[0])
if h['name'] == 'puppet-agent' and puppet_version == 1:
puppet_version = 4
return puppet_version
This works fine for Puppet 3, 4 and 5
@sideangleside whatcha think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evgeni If I am not getting wrong, we are comparing the puppet-agent packaging version here. I doubt if this will be future proof or not, in case packaging convention changes in future for the newer releases of Puppet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, it's using the packaging version. I would not expect the major version of the packaging to differ from the major version of the agent in the future (well, puppet4 agent is an exemption here :()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am strongly supportive of checking the RPMs version number as it is consistent with other checks for packages that we do. Additionally, checking via an executable's location is just as prone to packaging changes as anything else, so i'd want to be consistent.
bootstrap.py
Outdated
puppet_major_version = get_puppet_version() | ||
if puppet_major_version == 3: | ||
puppet_conf_file = '/etc/puppet/puppet.conf' | ||
elif puppet_major_version == 4: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make this puppet_major_version in [4,5]
? as Puppet5 uses the same path and that would make it more future proof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -218,6 +218,45 @@ def install_prereqs(): | |||
delete_file('/etc/yum.repos.d/katello-client-bootstrap-deps.repo') | |||
|
|||
|
|||
def get_puppet_path(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be then (if we use the RPMdb)
puppet_major_version = get_puppet_version()
if puppet_major_version == 3:
return '/usr/bin/puppet'
elif puppet_major_version in [4,5]:
return '/opt/puppetlabs/puppet/bin/puppet'
else:
error
Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
@evgeni Addressed the changes in the commit. Please review :) |
code LGTM 👍 I'll give it a few test runs later today and merge afterwards, unless @sideangleside is faster ;) |
So I gave it a fair spin, and it seems to work fine. However I spotted a few differences in the our:
foreman:
I think we should align this for the Puppet4/5 case. |
and with that change, we should also extend https://github.com/h4xr/katello-client-bootstrap/blob/2a9f0662d26b90042141a79cda9d216eb3118079/bootstrap.py#L384 to wipe |
bootstrap.py
Outdated
rundir = /var/run/puppet | ||
ssldir = /etc/puppetlabs/puppet/ssl | ||
""") | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that code is unreached, we already verified that it's version 3, 4 or 5 when looking for the conf path
bootstrap.py
Outdated
print_error("Unsupported puppet version") | ||
sys.exit(1) | ||
puppet_conf = open(puppet_conf_file, 'wb') | ||
if puppet_major_version == 3: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of having another set of if/elif
here, I'd put the dirs (or the whole [main]
section) into a variable during the conf path detection, and just use the variable in one write()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two comments, which would make the code a bit cleaner (IMHO), but neither is really blocking and the code works just fine as it is. ACK from me.
would love to hear a second ACK from @sideangleside before merging, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one functional, and two cosmetic comments, good to go when at least the functional is addressed.
bootstrap.py
Outdated
[main] | ||
vardir = /opt/puppetlabs/puppet/cache | ||
logdir = /var/log/puppetlabs/puppet | ||
rundir = /var/run/puppet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be /var/run/puppetlabs
bootstrap.py
Outdated
puppet_major_version = get_puppet_version() | ||
if puppet_major_version == 3: | ||
puppet_conf_file = '/etc/puppet/puppet.conf' | ||
main_section = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cosmetic: this makes main_section
start with a newline, and thus the generated puppet.conf
starts with two newlines. can we change this to main_section = """[main]…
?
bootstrap.py
Outdated
""" | ||
elif puppet_major_version in [4, 5]: | ||
puppet_conf_file = '/etc/puppetlabs/puppet/puppet.conf' | ||
main_section = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cosmetic: this makes main_section
start with a newline, and thus the generated puppet.conf
starts with two newlines. can we change this to main_section = """[main]…
?
Signed-off-by: Saurabh Badhwar <sbadhwar@redhat.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
waiting on @sideangleside
LGTM 👍 |
Thanks for the PR @h4xr |
* make bootstrap.py compatible with Puppet 4 (Katello#230) * add ansible example playbook (Katello#197) * remove SAMs CA consumer RPM in remove_obsolete_packages() (Katello#234) * allow FIPS enabled systems to register successfully with puppet (Katello#236) * allow configuring timeout for API calls and subscription-manager (Katello#237) * implement switching proxy / caps without destroying the host in Foreman (Katello#227)
Fixes #229
Signed-off-by: Saurabh Badhwar sbadhwar@redhat.com