Skip to content

Instantly share code, notes, and snippets.

@flyemsafe
Last active August 3, 2020 18:09
Show Gist options
  • Save flyemsafe/57a3d310ead37e14ddc5ba763df8dc34 to your computer and use it in GitHub Desktop.
Save flyemsafe/57a3d310ead37e14ddc5ba763df8dc34 to your computer and use it in GitHub Desktop.
ansible-tower

Tower Repos

[ansible-tower]
name=Ansible Tower Repository - $releasever $basearch
baseurl=http://releases.ansible.com/ansible-tower/rpm/epel-7-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[ansible-tower-dependencies]
name=Ansible Tower Dependencies Repository - $releasever $basearch
baseurl=http://releases.ansible.com/ansible-tower/rpm/dependencies/3.6/epel-7-$basearch
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Vars

ARCH="x86_64"
TYPE="infra"
PRODUCT="tower"
ROLE="${PRODUCT}-infra"
LC_ENVS="DEV PROD"
CV="cv-${TYPE}-${PRODUCT}"
CCV="ccv-lab-${ROLE}"

REPOS="$(mktemp)"
cat > $REPOS << EOF
'Ansible Tower Repository - 7 x86_64';'Ansible Tower'
'EPEL 7 x86_64';'Extra Packages for Enterprise Linux'
'Copr repo for rabbitmq owned by jlaska';'RabbitMQ by jlaska'
'PostgreSQL 9.6 7Server - x86_64';'PostgreSQL'
EOF

Create Content View

hammer content-view create --name "${CV}" --organization $ORG

while IFS=";" read repo cv_product;
do
 echo hammer content-view add-repository --name "${CV}" --organization $ORG \
    --product "${cv_product}" --repository "${repo}"
done < $REPOS|sh

Create Filter for EPEL

REPOID=$(hammer --csv repository list --name 'EPEL 7 x86_64' --organization $ORG | grep -vi '^ID' | awk -F',' '{print $1}')

hammer content-view filter create --type rpm --name 'tower-required-pkgs' \
--description 'Only include the pkgs required by Tower' --inclusion=true \
--repository-ids $REPOID --content-view "$CV" --organization "$ORG"

PKG_LIST="$(mktemp)"
cat > $PKG_LIST << EOF
bubblewrap
libtomcrypt
libtommath
lyx-fonts
nginx
nginx-all-modules
nginx-filesystem
nginx-mod-http-geoip
nginx-mod-http-image-filter
nginx-mod-http-perl
nginx-mod-http-xslt-filter
nginx-mod-mail
nginx-mod-stream
python2-crypto
python2-psutil
python-meld3
python-paramiko
sshpass
supervisor
EOF

while read pkg
do
  echo hammer content-view filter rule create --name "'$pkg'" --content-view "$CV" --content-view-filter 'tower-required-pkgs' --organization "$ORG"
done < $PKG_LIST

hammer content-view publish --name "${CV}" --organization $ORG \
    --description "Initial publish"

CVID=$(hammer --csv content-view list --name "${CV}" --organization ${ORG} | grep -vi '^Content View ID,' | awk -F',' '{print $1}')

IFS=" "
for LC in $(echo $LC_ENVS);
do
  promote_content $LC $CVID "$ORG" "${CV}"
done

Create Ansible Composite View

RHEL7_CB_VID=`get_latest_version cv-os-rhel-7Server`
APP_CVID=`get_latest_version "${CV}"`
ANSIBLE_CVID=$(get_latest_version cv-infra-ansible)

echo "hammer content-view create --name "${CCV}" \
--composite --description 'CCV for Lab ${Product} Server' \
--organization $ORG --component-ids ${RHEL7_CB_VID},${APP_CVID},${ANSIBLE_CVID}"

hammer content-view publish --name "${CCV}" --organization "$ORG"

CVID=$(hammer --csv content-view list --name "${CCV}" --organization ${ORG} | grep -vi '^Content View ID,' | awk -F',' '{print $1}')
APP_CVID=`get_latest_version ${CCV}`

IFS=" "
for LC in $(echo $LC_ENVS);
do
  promote_content $LC $CVID "$ORG" ${CCV}
  sleep 1
done
  • Activation Key
CV="${CCV}"
for LC_ENV in ${LC_ENVS}
do
LC_ENV_LOWER=$(echo ${LC_ENV} | tr '[[:upper:]' '[[:lower:]]')
LC_ENV_UPPER=$(echo ${LC_ENV} | tr '[[:lower:]' '[[:upper:]]')
echo hammer activation-key create --name "act-${LC_ENV_LOWER}-${TYPE}-${ROLE}-${ARCH}" \
   --content-view "$CV" --lifecycle-environment "${LC_ENV}" --organization "${ORG}"

#TODO adding subscriptions needs some work
SubRHEL=$(hammer --csv --csv-separator '#' subscription list --per-page 9999 --organization ${ORG} | awk -F'#' '/Employee SKU/ {print $1}')
SubEPEL=$(hammer --csv --csv-separator '#' subscription list --per-page 9999 --organization ${ORG} | awk -F'#' '/Extra Packages for Enterprise Linux/ {print $1}')
SubTOWER=$(hammer --csv --csv-separator '#' subscription list --per-page 9999 --organization ${ORG} | awk -F'#' '/Ansible Tower/ {print $1}')
SubRABBIT=$(hammer --csv --csv-separator '#' subscription list --per-page 9999 --organization ${ORG} | awk -F'#' '/RabbitMQ by jlaska/ {print $1}')
SubPGSQL=$(hammer --csv --csv-separator '#' subscription list --per-page 9999 --organization ${ORG} | awk -F'#' '/PostgreSQL/ {print $1}')

SubIDs="${SubRHEL},${SubEPEL},${SubTOWER},${SubRABBIT},${SubPGSQL}"
for SubID in ${SubIDs}
do
echo hammer activation-key add-subscription --name "act-${LC_ENV_LOWER}-${TYPE}-${ROLE}-${ARCH}" --subscription-id "${SubID}" --organization "${ORG}"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment