From fb7bdd068208291e88175bda774deb0e72e3322a Mon Sep 17 00:00:00 2001 From: Nick Maludy Date: Mon, 12 Oct 2020 14:12:07 -0400 Subject: [PATCH] Fixing changes from code review. Adding Ubuntu support to MongoDB upgrade plan --- manifests/profile/nginx.pp | 2 +- manifests/repo.pp | 4 +- plans/upgrade_mongodb.pp | 105 +++++++++++++++++++++++++++++++------ 3 files changed, 92 insertions(+), 19 deletions(-) diff --git a/manifests/profile/nginx.pp b/manifests/profile/nginx.pp index 9188a70e..0e6b28b7 100644 --- a/manifests/profile/nginx.pp +++ b/manifests/profile/nginx.pp @@ -6,7 +6,7 @@ # @example Basic Usage # include st2::profile::nginx # -# @example Disable manging the nginx repo so you can manage it yourself +# @example Disable managing the nginx repo so you can manage it yourself # class { 'st2::profile::nginx': # manage_repo => false, # } diff --git a/manifests/repo.pp b/manifests/repo.pp index 90c0c85a..e97360cb 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -16,8 +16,8 @@ # class st2::repo ( Enum['present', 'absent'] $ensure = 'present', - St2::Repository $repository = 'stable', -) { + St2::Repository $repository = $st2::repository, +) inherits st2 { case $facts['os']['family'] { 'RedHat': { # RedHat distros need EPEL diff --git a/plans/upgrade_mongodb.pp b/plans/upgrade_mongodb.pp index 8f89087d..b43c6342 100644 --- a/plans/upgrade_mongodb.pp +++ b/plans/upgrade_mongodb.pp @@ -29,6 +29,10 @@ # @param [Array[String]] mongo_packages # List of MongoDB packages that will be upgraded # +# @param [Enum['enterprise', 'org']] mongo_edition +# What edition of MongoDB should be setup from a repo perspective, +# either 'org' for community edition, or 'enterprise' for enterprise edition. +# # @param [String] upgrade_version_start # Version of MongoDB that the database is currently on, ie. where we are starting from. # @@ -39,7 +43,7 @@ # bolt plan run st2::upgrade_mongodb --targets ssh_nodes --params '{"mongo_password": "xxx"}' # # @example Upgrading enterprise packages -# bolt plan run st2::upgrade_mongodb --targets ssh_nodes --params '{"mongo_password": "xxx", "mongo_packages": ["mongodb-enterprise-server", "mongodb-enterprise-shell", "mongodb-enterprise-tools"]}' +# bolt plan run st2::upgrade_mongodb --targets ssh_nodes --params '{"mongo_password": "xxx", "mongo_packages": ["mongodb-enterprise-server", "mongodb-enterprise-shell", "mongodb-enterprise-tools"], "mongo_edition": "enterprise"}' # # @example Upgrading from 3.6 to 4.0 # bolt plan run st2::upgrade_mongodb --targets ssh_nodes --params '{"mongo_password": "xxx", "upgrade_version_start": "3.6", "upgrade_version_path": ["4.0"]}' @@ -52,6 +56,7 @@ String $mongo_username = 'admin', String $mongo_password, Array[String] $mongo_packages = ['mongodb-org-server', 'mongodb-org-shell', 'mongodb-org-tools'], + Enum['enterprise', 'org'] $mongo_edition = 'org', String $upgrade_version_start = '3.4', Array[String] $upgrade_version_path = ['3.6', '4.0'], TargetSpec $targets, @@ -63,36 +68,104 @@ # set MongoDB feature compatibility to 3.4 $start_ver = $upgrade_version_start - run_command("$mongo_cmd --eval \"db.adminCommand( { setFeatureCompatibilityVersion: '$start_ver' } )\"", + run_command("$mongo_cmd --eval \"db.adminCommand( { setFeatureCompatibilityVersion: '${start_ver}' } )\"", $targets, - "Mongodb - Set Feature Compatibility Version $start_ver") + "Mongodb - Set Feature Compatibility Version ${start_ver}") + + # gather facts on the targets so that we can determine RHEL/CentOS vs Ubuntu + run_plan('facts', $targets) $upgrade_version_path.each |$ver| { - # Chnage Yum repo to this version + # Change Yum repo to this version apply($targets) { - yumrepo { 'mongodb': - descr => 'MongoDB Repository', - baseurl => "https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/${ver}/\$basearch/", - gpgcheck => '0', - enabled => '1', + if ($facts['os']['family'] == 'RedHat') { + yumrepo { 'mongodb': + descr => 'MongoDB Repository', + baseurl => "https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/${ver}/\$basearch/", + gpgcheck => '0', + enabled => '1', + notify => Exec['yum_clean_all'], + } + + # rebuild yum cache since we just changed repositories + exec { 'yum_clean_all': + command => '/usr/bin/yum clean all', + refreshonly => true, + notify => Exec['yum_makecache_fast'], + } + exec { 'yum_makecache_fast': + command => '/usr/bin/yum makecache fast', + refreshonly => true, + } + } + else { + if $mongo_edition == 'enterprise' { + $repo_domain = 'repo.mongodb.com' + $repo_path = 'mongodb-enterprise' + } else { + $repo_domain = 'repo.mongodb.org' + $repo_path = 'mongodb-org' + } + + $mongover = split($ver, '[.]') + $location = $facts['os']['name'] ? { + 'Debian' => "https://${repo_domain}/apt/debian", + 'Ubuntu' => "https://${repo_domain}/apt/ubuntu", + default => undef + } + $release = "${facts['os']['distro']['codename']}/${repo_path}/${mongover[0]}.${mongover[1]}" + $repos = $facts['os']['name'] ? { + 'Debian' => 'main', + 'Ubuntu' => 'multiverse', + default => undef + } + $key = "${mongover[0]}.${mongover[1]}" ? { + '4.4' => '20691EEC35216C63CAF66CE1656408E390CFB1F5', + '4.2' => 'E162F504A20CDF15827F718D4B7C549A058F8B6B', + '4.0' => '9DA31620334BD75D9DCB49F368818C72E52529D4', + '3.6' => '2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5', + '3.4' => '0C49F3730359A14518585931BC711F9BA15703C6', + '3.2' => '42F3E95A2C4F08279C4960ADD68FA50FEA312927', + default => '492EAFE8CD016A07919F1D2B9ECBEC467F0CEB10' + } + $key_server = 'hkp://keyserver.ubuntu.com:80' + + apt::source { 'mongodb': + location => $location, + release => $release, + repos => $repos, + key => { + 'id' => $key, + 'server' => $key_server, + }, + notify => Exec['apt-get-clean'], + } + + # rebuild apt cache since we just changed repositories + exec { 'apt-get-clean': + command => '/usr/bin/apt-get clean', + refreshonly => true, + notify => Exec['apt-get-update'], + } + exec { 'apt-get-update': + command => '/usr/bin/apt-get -y update', + refreshonly => true, + } } } - # rebuild yum cache since we just changed repositories - run_command('yum clean all', $targets) - run_command('yum makecache fast', $targets) # Upgrade packages $mongo_packages.each |$package| { run_task('package::linux', $targets, - name => $package, - action => 'upgrade') + name => $package, + action => 'upgrade') } # Set compatibility level to this version - run_command("$mongo_cmd --eval \"db.adminCommand( { setFeatureCompatibilityVersion: '$ver' } )\"", + run_command("$mongo_cmd --eval \"db.adminCommand( { setFeatureCompatibilityVersion: '${ver}' } )\"", $targets, - "Mongodb - Set Feature Compatibility Version $ver") + "Mongodb - Set Feature Compatibility Version ${ver}") } # start stackstorm