Skip to content

Instantly share code, notes, and snippets.

@omaciel
Last active August 24, 2016 18:40
Show Gist options
  • Save omaciel/5709991 to your computer and use it in GitHub Desktop.
Save omaciel/5709991 to your computer and use it in GitHub Desktop.
A simple Katello CLI script to automatically download a product manifest, import it into a Katello organization and create content. It assumes that you have the following information (either as environmental variables or substituted into the script: ``` RHN_USERNAME: A valid username for https://access.redhat.com/ RHN_PASSWORD: A valid password …
#!/bin/bash
function kk() {
KATELLO_PATH=/usr/bin/katello
$KATELLO_PATH -u admin -p admin "$@"
}
ORG='SimpleOrg'
# Orgs
## Simple Org
kk org create --name $ORG
kk environment create --org $ORG --name 'Dev Env' --prior Library
kk environment create --org $ORG --name 'QA Env' --prior 'Dev Env'
kk environment create --org $ORG --name 'GA Env' --prior 'QA Env'
# Switch to $ORG Org
kk client remember --option org --value $ORG
kk client remember --option env --value 'Dev Env'
# RHEL content
## Import manifest: Change FQDN to where your manifest lives
curl -o /tmp/manifest.zip -u $RHN_USERNAME:$RHN_PASSWORD -X GET "https://subscription.rhn.redhat.com/subscription/consumers/$DISTRIBUTOR/export" --insecure --fail
kk provider import_manifest --name "Red Hat" --file /tmp/manifest.zip
kk product repository_set_enable --name "Red Hat Enterprise Linux Server" --set_name "Red Hat Enterprise Linux 6 Server (RPMs)"
kk repo enable --product "Red Hat Enterprise Linux Server" --name "Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server"
# Custom provider
kk provider create --name="Google"
wget https://dl-ssl.google.com/linux/linux_signing_key.pub
kk gpg_key create --name 'google-gpg' --file linux_signing_key.pub
# Google product
kk product create --name="Chrome" --provider="Google"
kk product update --name="Chrome" --gpgkey 'google-gpg'
kk repo create --name="google-chrome-32bit" --product="Chrome" --url=http://dl.google.com/linux/chrome/rpm/stable/i386 --unprotected
kk repo create --name="google-chrome-64bit" --product="Chrome" --url=http://dl.google.com/linux/chrome/rpm/stable/x86_64 --unprotected
# Sync 1
kk provider synchronize --name Google
# Sync 2
kk provider synchronize --name "Red Hat"
# Content View Definition 1 with a filter on packages
kk content definition create --name ChromeCVD --description 'Google Chrome Browser Content View Definition'
kk content definition add_repo --name ChromeCVD --product Chrome --repo google-chrome-64bit
kk content definition filter create --name stable_chrome --definition ChromeCVD
kk content definition filter add_repo --definition ChromeCVD --name stable_chrome --product Chrome --repo google-chrome-64bit
kk content definition filter add_rule --definition ChromeCVD --name stable_chrome --content rpm --type includes --rule '{"units": [{"name": "google-chrome-stable"}]}'
kk content definition publish --name ChromeCVD --view_name 'PublishedChrome' --description 'Contains Google Chrome stable version only.'
# Content View Definition 2
kk content definition create --name RHELCVD --description 'Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server'
kk content definition add_product --name RHELCVD --product "Red Hat Enterprise Linux Server"
kk content definition filter create --name removed_errata --definition RHELCVD64
kk content definition filter add_repo --definition RHELCVD64 --name removed_errata --product 'Red Hat Enterprise Linux Server' --repo 'Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server'
kk content definition filter add_rule --definition RHELCVD64 --name removed_errata --content erratum --type excludes --rule '{"units": [{"id": "RHBA-2010:0836"}]}'
kk content definition publish --name RHELCVD --view_name 'PublishedRHEL' --description 'Contains Red Hat Enterprise Linux 6 Server RPMs x86_64 6Server'
# Composite Content View Definition 1
kk content definition create --name CompositeCVD --description 'All available content views into one.' --composite
kk content definition add_view --name CompositeCVD --content_view PublishedChrome
kk content definition add_view --name CompositeCVD --content_view PublishedRHEL
kk content definition publish --name CompositeCVD --view_name 'PublishedComposite' --description 'Contains RHEL and Google Chrome.'
# Promote Composite Content View 1
kk changeset create --name Promote1 --description 'First time to Dev Env' --environment 'Dev Env'
kk changeset update --name Promote1 --environment 'Dev Env' --add_content_view PublishedChrome
kk changeset update --name Promote1 --environment 'Dev Env' --add_content_view PublishedRHEL
kk changeset update --name Promote1 --environment 'Dev Env' --add_content_view PublishedComposite
kk changeset promote --name Promote1 --environment 'Dev Env'
# Sync plans
## Hourly sync for Google starting 20 minutes from now
kk sync_plan create --interval hourly --date `date +"%Y-%m-%d"` --time `date -d "+20 minute" +"%H:%M:%S"` --name "Hourly"
kk product set_plan --name "Chrome" --plan Hourly
## Weekly sync for RHEL
kk sync_plan create --interval weekly --date `date +"%Y-%m-%d"` --name "Weekly"
kk product set_plan --name "Red Hat Enterprise Linux Server" --plan Weekly
# Activation Keys
## All Products for DEV
kk activation_key create --name ActivationKey1 --environment 'Dev Env'
kk activation_key update --name ActivationKey1 --environment 'Dev Env' --content_view PublishedComposite
## Add all subscriptions to ActivationKey1
for i in `kk org subscriptions --name $ORG -g -d ',' --noheading | awk -F ',' '{print $3}'`; do kk activation_key update --name ActivationKey1 --add_subscription $i; done
# Create system groups
kk system_group create --name SystemGroup1 --description 'Systems with access to RHEL and Google Chrome'
kk activation_key add_system_group --name ActivationKey1 --system_group SystemGroup1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment