Commit 5c32e387 authored by Choon Ming Goh's avatar Choon Ming Goh

add initial setup script

parent f68f6814
Pipeline #380 passed with stages
in 3 minutes
......@@ -34,6 +34,11 @@ We have three different style of deployment.
* For trying out Opstheater for later production deployment, please use thi instructions (this moment we suggest you to use the “develop” branch).
To install OpsTheater directly onto your Puppet Server, do the following:
```
curl https://gitlab.olindata.com/opstheater/opstheater/raw/2.0.0-stable/deploy/setup.sh | bash -s -- -b <branch_name> -d <domain> -u <control repo url>
```
## Need Help?
Need help? Try one of these:
......
#!/bin/bash
BRANCH=$GIT_BRANCH
DOMAIN=$OT_DOMAIN
CONTROL_REPO_URL=$GIT_CONTROL_REPO
while getopts b:d:u: option
do
case "${option}"
in
b) BRANCH=${OPTARG};;
d) DOMAIN=${OPTARG};;
u) CONTROL_REPO_URL=${OPTARG};;
esac
done
echo $BRANCH
echo $DOMAIN
echo $CONTROL_REPO_URL
exit 0
echo "Running setup-foss-master.sh"
# 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 $BRANCH | tr '.\-/' _)
log "==> stopping firewalld service" norm
if [ -f /usr/lib/systemd/system/firewalld.service ]; then
service firewalld stop || { log "==> $SIGN_ERR failed to stop firewalld service" err ; exit 1; }
elif [ -f /usr/lib/systemd/system/iptables.service ]; then
service iptables stop || { log "==> $SIGN_ERR failed to stop iptables service" err; exit 1; }
else
log "no firewalld or iptables service found" norm
fi
log "==> $SIGN_OK 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 "==> $SIGN_ERR 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 "==> $SIGN_ERR 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 "==> $SIGN_ERR 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 "==> $SIGN_ERR failed to install foreman-installer" err ; exit 1; }
fi
log "==> $SIGN_OK 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 "==> $SIGN_OK OK:enabling postgresql repository" ok
log "==> installing puppet and foreman dashboard" norm
foreman-installer \
--no-colors \
--foreman-proxy-tftp false \
--foreman-proxy-dhcp false \
--foreman-proxy-bmc false \
--foreman-proxy-dns false \
--puppet-autosign-entries "*.${DOMAIN}" \
--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
CREDENTIALS=$(foreman-installer --no-colors | grep -i "credentials")
log "==> $SIGN_OK 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":
"hostname": ".*"
EOF
log "==> $SIGN_OK 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 "class { 'puppetdb': manage_firewall => false} include puppetdb::master::config" --detailed-exitcodes
if [ $? == 4 ] || [ $? == 6 ]; then
log "==> $SIGN_ERR puppet agent run encountered errors" err
exit 1
fi
log "==> $SIGN_OK OK:installing puppetdb" ok
# needed for grafana module
/opt/puppetlabs/bin/puppetserver gem install toml
log "==> stopping firewalld service" norm
if [ -f /usr/lib/systemd/system/firewalld.service ]; then
service firewalld stop || { log "==> $SIGN_ERR failed to stop firewalld service" err ; exit 1; }
elif [ -f /usr/lib/systemd/system/iptables.service ]; then
service iptables stop || { log "==> $SIGN_ERR failed to stop iptables service" err; exit 1; }
else
log "no firewalld or iptables service found" norm
fi
log "==> $SIGN_OK 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 => "${CONTROL_REPO_URL}",
r10k_basedir => $::settings::environmentpath,
}
EOF
/opt/puppetlabs/bin/puppet apply /tmp/r10k.pp --detailed-exitcodes
if [ $? == 4 ] || [ $? == 6 ]; then
log "==> puppet apply run encountered errors" err
exit 1
fi
log "==> $SIGN_OK 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 $BRANCH -pv debug
log "==> $SIGN_OK OK:deploying r10k environments" ok
log "==> importing puppet environments to foreman" norm
hammer proxy import-classes --id 1
if [ $? == 1 ]; then
log "==> $SIGN_ERR importing classed encountered errors" err
exit 1
fi
log "==> $SIGN_OK OK:importing puppet environments to foreman" ok
log "==> creating default hostgroups" norm
hammer hostgroup create --name "OpsTheater" --puppet-proxy-id 1 --puppet-ca-proxy-id 1 --environment $PUPPET_ENV --locations Global --organizations OpsTheater
hammer hostgroup create --name "Elastic" --parent "OpsTheater" --puppet-classes "opstheater::role::elastic::server"
hammer hostgroup create --name "MySQL" --parent "OpsTheater" --puppet-classes "opstheater::role::database::standalone"
hammer hostgroup create --name "Icinga" --parent "OpsTheater" --puppet-classes "opstheater::role::monitoring::standalone"
hammer hostgroup create --name "Gitlab" --parent "OpsTheater" --puppet-classes "opstheater::role::gitlab::server"
hammer hostgroup create --name "Puppet" --parent "OpsTheater" --puppet-classes "opstheater::role::puppet::master"
log "==> $SIGN_OK 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 'Puppet' --organization OpsTheater --location Global
hammer user create --admin true --firstname api --lastname user --locations Global --organizations OpsTheater --login opstheater --password opstheater --mail api@opstheater.com --auth-source-id 1
log "==> configuring hiera.yaml" norm
# the new hiera version in puppet 4.9.0 hard errors when older hiera config files are found inside environments
# the following ugly hack makes things work for now
mv /etc/puppetlabs/code/environments/production/hiera.yaml /etc/puppetlabs/puppet/hiera.yaml
rm -f /etc/puppetlabs/code/environments/*/hiera.yaml
log "==> $SIGN_OK OK:configuring hiera.yaml" ok
service httpd restart
service puppetserver restart
log "==> running puppet agent" norm
/opt/puppetlabs/bin/puppet agent -t --detailed-exitcodes
if [ $? == 4 ] || [ $? == 6 ]; then
log "==> $SIGN_ERR puppet agent run encountered errors" err
exit 1
fi
log "==> $SIGN_OK OK: running puppet agent" ok
/opt/puppetlabs/bin/puppet resource service firewalld ensure=stopped enable=false
echo "Foreman URL: https://$HOSTNAME"
echo "$CREDENTIALS"
echo "Finishing setup-foss-master.sh"
......@@ -61,7 +61,7 @@ roles:
foss-puppet-master:
provisioners:
- type: shell
path: files/setup-foss-master.sh
path: files/setup.sh
env:
GIT_BRANCH: <%= ENV['GIT_BRANCH'] %>
OT_DOMAIN: <%= ENV['OT_DOMAIN'] %>
......
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