Commit 3c1fa673 authored by Walter Heck's avatar Walter Heck

remove merge mistake

parent 44d3b882
Pipeline #363 passed with stages
in 2 minutes and 25 seconds
#!/bin/bash
# colorize some of the output, see http://dcmnt.me/1XYnkPe for more information
COLOR_OK=$(tput setaf 2)
COLOR_ERR=$(tput setaf 1)
COLOR_OFF=$(tput sgr0)
COLOR_BRIGHT=$(tput bold)
SIGN_OK="${COLOR_OFF} ${COLOR_OK}${COLOR_OFF}"
SIGN_ERR="${COLOR_OFF} ${COLOR_ERR}${COLOR_OFF}"
function log {
case $2 in
norm)
message="${COLOR_BRIGHT}${1}${COLOR_OFF}"
;;
ok)
message="${COLOR_OK}${1}${COLOR_OFF}"
;;
err)
message="${COLOR_ERR}${1}${COLOR_OFF}"
;;
esac
echo "$message" >&2
}
#convert all hyphens and forward slashes to underscore
PUPPET_ENV=$(echo $GIT_BRANCH | sed s'/[-//]/_/g')
log "==> stopping firewalld service" norm
if [ -f /usr/lib/systemd/system/firewalld.service ]; then
service firewalld stop || { log "==> failed to stop firewalld service" err ; exit 1; }
elif [ -f /usr/lib/systemd/system/iptables.service ]; then
service iptables stop || { log "==> failed to stop iptables service" err; exit 1; }
else
log "no firewalld or iptables service found" norm
fi
log "==> OK:stopping firewalld service" ok
log "==> installing necessary yum repositories and foreman-installer" norm
if rpm -q puppetlabs-release-pc1-el-7; then
log "==> puppetlabs-release-pc1-el-7 already installed, skipping" norm
else
rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm || { log "==> failed to install puppetlabs pc1 rpm" err; exit 1; }
fi
if rpm -q epel-release; then
log "==> epel-release already installed, skipping" norm
else
yum -y install epel-release || { log "==> failed to install epel-release" err; exit 1; }
fi
if rpm -q foreman-release; then
log "==> foreman-release already installed, skipping" norm
else
yum -y install https://yum.theforeman.org/releases/1.13/el7/x86_64/foreman-release.rpm || { log "==> failed to install foreman-release" err; exit 1; }
fi
if rpm -q foreman-installer; then
log "==> foreman-installer already installed, skipping" norm
else
yum install -y foreman-installer || { log "==> failed to install foreman-installer" err ; exit 1; }
fi
log "==> OK:installing necessary yum repositories and foreman-installer" ok
log "==> enabling postgresql repository" norm
echo "postgresql::globals::version: '9.4'" >> /usr/share/foreman-installer/config/foreman.hiera/RedHat.yaml
echo "postgresql::globals::manage_package_repo: true" >> /usr/share/foreman-installer/config/foreman.hiera/RedHat.yaml
log "==> OK:enabling postgresql repository" ok
log "==> installing puppet and foreman dashboard" norm
CREDENTIALS=$(foreman-installer -v \
--verbose-log-level warn --no-colors \
--puppet-autosign-entries '*.opstheater.vm' \
--puppet-environment $PUPPET_ENV \
--foreman-configure-epel-repo false \
--foreman-locations-enabled true \
--foreman-organizations-enabled true \
--foreman-initial-location Global \
--foreman-initial-organization OpsTheater \
--enable-foreman-plugin-default-hostgroup \
--enable-foreman-plugin-puppetdb \
--foreman-plugin-puppetdb-dashboard-address http://localhost:8080/pdb/dashboard > /dev/null \
&& foreman-installer -v --verbose-log-level warn --no-colors | grep -i "credentials")
log "==> OK:installing puppet and foreman dashboard" ok
#fetch server hostname
HOSTNAME=$(/opt/puppetlabs/puppet/bin/facter fqdn)
log "==> configure default hostgroup plugin" norm
cat <<EOF > /etc/foreman/plugins/default_hostgroup.yaml
---
:default_hostgroup:
:facts_map:
"OpsTheater Infra":
"hostname": ".*"
EOF
log "==> OK:configure default hostgroup plugin" ok
source /etc/profile
log "==> installing puppetdb" norm
/opt/puppetlabs/bin/puppet module install puppetlabs/puppetdb || { log "==> $SIGN_ERR failed to install puppetdb puppet module" ; exit 1; }
/opt/puppetlabs/bin/puppet apply -e 'include puppetdb, puppetdb::master::config'
log "==> OK:installing puppetdb" ok
log "==> stopping firewalld service" norm
if [ -f /usr/lib/systemd/system/firewalld.service ]; then
service firewalld stop || { log "==> failed to stop firewalld service" err ; exit 1; }
elif [ -f /usr/lib/systemd/system/iptables.service ]; then
service iptables stop || { log "==> failed to stop iptables service" err; exit 1; }
else
log "no firewalld or iptables service found" norm
fi
log "==> OK:stopping firewalld service" ok
log "==> configuring R10K" norm
/opt/puppetlabs/bin/puppet module install zack/r10k || { log "==> $SIGN_ERR failed to install r10k puppet module" ; exit 1; }
cat <<EOF > /tmp/r10k.pp
class { '::r10k':
remote => 'https://gitlab.olindata.com/opstheater/opstheater.git',
r10k_basedir => $::settings::environmentpath,
}
EOF
/opt/puppetlabs/bin/puppet apply /tmp/r10k.pp
log "==> OK:configuring R10K" ok
log "==> deploying r10k environments" norm
# always check out production (it contains the hiera.yaml file), but possibly also the current branch
/opt/puppetlabs/puppet/bin/r10k deploy environment production $GIT_BRANCH -pv debug
log "==> OK:deploying r10k environments" ok
log "==> importing puppet environments to foreman" norm
hammer proxy import-classes --id 1
log "==> OK:importing puppet environments to foreman" ok
log "==> creating default hostgroup" norm
hammer hostgroup create --name "OpsTheater Infra" --puppet-proxy-id 1 --puppet-ca-proxy-id 1 --environment $PUPPET_ENV --locations Global --organizations OpsTheater
log "==> OK:creating default hostgroup" ok
hammer organization update --name OpsTheater --environments $PUPPET_ENV
hammer location update --name Global --environments $PUPPET_ENV
hammer host update --name $HOSTNAME --hostgroup 'OpsTheater Infra' --organization OpsTheater --location Global
log "==> configuring hiera.yaml" norm
/opt/puppetlabs/bin/puppet config set hiera_config /etc/puppetlabs/code/environments/production/hiera.yaml
log "==> OK:configuring hiera.yaml" ok
service httpd restart
service puppetserver restart
/opt/puppetlabs/bin/puppet agent -t || true
echo "Foreman URL: https://$HOSTNAME"
echo "$CREDENTIALS"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment