Skip to content

Commit

Permalink
Add 6.3 puppet 4 support
Browse files Browse the repository at this point in the history
Fixes #328
  • Loading branch information
John Mitsch committed Jun 18, 2018
1 parent cf32238 commit b0de5e6
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 57 deletions.
50 changes: 0 additions & 50 deletions library/check_metadata_for_satellite_version.py

This file was deleted.

96 changes: 96 additions & 0 deletions library/parse_backup_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import yaml
import re
from ansible.module_utils.basic import *


# module: parse_backup_metadata
# description:
# - Return the Satellite version and Puppet version
# specified in a Satellite backup
# notes:
# - The Satellite version is determined from the Satellite rpm
# version using the backup's rpm list from metadata.yml
# - The puppet version is determined from the presence of
# puppet and puppet-agent rpms
# options:
# metadata_path:
# description:
# - Full path (including file name) to metadata.yml
# required: true

SUPPORTED_VERSIONS = ["6.2", "6.3"]

def find_rpm(rpms, pattern):
matches = [r for r in rpms if pattern.match(r)]
if len(matches) > 0:
return matches[0]
else:
return False


def get_rpm_version(rpms, pattern, hyphen_split=1, version_split=2):
rpm_pattern = re.compile(pattern)
rpm = find_rpm(rpms, rpm_pattern)
if rpm:
rpm_version = rpm.split("-")[hyphen_split]
return '.'.join(rpm_version.split('.')[0:version_split])
else:
return False


def get_puppet_version(puppet_agent_version, puppet_rpm_version):
error_msg = "Puppet version not found"
# Only puppet 4+ has puppet-agent rpm
if puppet_agent_version:
if puppet_agent_version == "1":
return "4"
elif puppet_agent_version == "5":
return "5"
else:
raise error_msg
# Puppet 3 contains "puppet-" rpm and puppet 4+ does not.
elif puppet_rpm_version:
return "3"
else:
raise error_msg


def parse_backup_metadata(params):
with open(params["metadata_path"]) as data_file:
data = yaml.load(data_file)

rpm_key = ":rpms" if ":rpms" in data else "rpms"
rpms = data[rpm_key]
satellite_version = get_rpm_version(rpms, "^satellite-[\d+].*")
puppet_agent_version = get_rpm_version(rpms, "^puppet-agent-[\d+].*", 2, 1)
puppet_rpm_version = get_rpm_version(rpms, "^puppet-[\d+].*", 1, 1)
puppet_version = get_puppet_version(puppet_agent_version, puppet_rpm_version)

if not satellite_version or satellite_version not in SUPPORTED_VERSIONS:
msg = "Satellite version is not supported or found. " \
"Only Satellite {0} is supported.".format(", ".join(SUPPORTED_VERSIONS))
return False, dict(msg=msg)

msg = "{0} backup found".format(satellite_version)
result = dict(satellite_version=satellite_version,
puppet_version=puppet_version,
msg=msg,
changed=False)
return True, result


def main():
fields = {
"metadata_path": {"required": True, "type": "str"}
}

module = AnsibleModule(argument_spec=fields)
success, result = parse_backup_metadata(module.params)
if success:
module.exit_json(**result)
else:
module.fail_json(**result)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions roles/satellite-clone/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ disable_postgres_triggers: True
restorecon: False
skip_satellite_rpm_check: False
overwrite_etc_hosts: True
puppet_version: 3
11 changes: 6 additions & 5 deletions roles/satellite-clone/tasks/backup_satellite_version_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
when: not clone_satellite_answers

- name: Check for satellite version in metadata file
check_metadata_for_satellite_version:
parse_backup_metadata:
metadata_path: "{{ backup_dir }}/metadata.yml"
register: metadata_satellite_version
register: backup_metadata
when: clone_metadata_exists

- name: setting fact - satellite_version
set_fact:
satellite_version: "{{ metadata_satellite_version.satellite_version }}"
satellite_version: "{{ backup_metadata.satellite_version }}"
puppet_version: "{{ backup_metadata.puppet_version }}"
cacheable: true
when:
- clone_metadata_exists
- metadata_satellite_version is defined
- metadata_satellite_version | success
- backup_metadata is defined
- backup_metadata | success
19 changes: 17 additions & 2 deletions roles/satellite-clone/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
register: enable_repos_result
when: enable_repos

- name: "Enable puppet repos"
command: subscription-manager repos --enable rhel-7-server-satellite-{{ satellite_version }}-puppet{{ puppet_version }}-rpms
when:
- enable_repos
- puppet_version | int >= 4

- name: set fact - enable_repos_result
set_fact:
enable_repos_result_fail: "{{ (enable_repos_result.rc | int) != 0}}"
Expand Down Expand Up @@ -157,10 +163,19 @@
file: path=/etc/katello-installer state=directory mode=0755
when: satellite_version in ["6.2", "6.3"]

# Restore Config
# If there is no puppet user, the extracted config files will not have the correct puppet
# user/group permissions with puppet 4. Installing puppetserver before extracting config_files
# fixes this issue.
- name: Install puppetserver to create puppet user
yum:
name: puppetserver
state: latest
when: puppet_version | int >= 4

- name: untar config files (for cloning only)
command: tar --selinux --overwrite -xf {{ backup_dir }}/config_files.tar.gz -C /
when: not rhel_migration

- name: untar config files (for migration only)
# rhel7's /etc/httpd/conf.d/passenger.conf is not backward compatible with rhel6
command: tar --selinux --overwrite -xf {{ backup_dir }}/config_files.tar.gz --exclude=etc/httpd/conf.d/passenger.conf -C /
Expand Down Expand Up @@ -222,7 +237,7 @@
when: satellite_version in ["6.2", "6.3"]

- name: Run installer upgrade (satellite 6.2+ only)
command: satellite-installer --upgrade
command: 'satellite-installer --upgrade {{ satellite_upgrade_options | default("") }}'
environment:
HOSTNAME: "{{ hostname }}"
when: satellite_version in ["6.2", "6.3"]
Expand Down
1 change: 1 addition & 0 deletions roles/satellite-clone/vars/satellite_6.3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ satellite_installer_cmd: satellite-installer
satellite_scenario: satellite
capsule_puppet_module: foreman-proxy
satellite_installer_options: "--foreman-ipa-authentication false --disable-system-checks"
satellite_upgrade_options: "--disable-system-checks"
verify_rake_task: reimport

0 comments on commit b0de5e6

Please sign in to comment.