Publish and promote content views automatically for system patching

Latest response

Hi,

I am pretty sure there might be a better way to achieve this, i came up with a workaround to publish and promote content view automatically using cron and mini scripts since at the moment there doesn't seem to be a way to set it up from the UI.

Below are the cron jobs set up with crontab -e as an example that run from 1 AM to 4 AM from the Satellite server:

# every 5th of the month from 1AM to 4 am - publish rhel7 server CV RPM to the library
0 1 5 * * /root/cv_promotion_scripts/publish_rhel7-server_library.sh
# promote to dev
0 2 5 * *  /root/cv_promotion_scripts/promote_rhel7-server_dev.sh
#promote to test
0 3 5 * * /root/cv_promotion_scripts/promote_rhel7-server_test.sh
#promote to prod
0 4 5 * * /root/cv_promotion_scripts/promote_rhel7-server_prod.sh

Below how publish and promote scripts look like:

publish_rhel7-server_library.sh

#!/bin/bash

/bin/hammer content-view publish --organization ORG --name 'rhel 7 server' --description 'latest monthly RPMs' --async  > /dev/null 2>&1

promote_rhel7-server_dev.sh

#!/bin/bash

# this variable selects the latest published version available in the content view and will be passed as a parameter to hammer
LATEST_VERS=`/bin/hammer content-view version list --content-view "rhel 7 server"  --organization ORG |awk '{print $6}'|sort -nr | head -n1`

/bin/hammer content-view version promote --version $LATEST_VERS --organization "ORG" --content-view  'rhel 7 server' --to-lifecycle-environment dev --force --async  > /dev/null 2>&1

now it is easy to invoke hammer to trigger a job execution that runs yum update by selecting the host collection id.

hammer job-invocation create --job-template "Run Command - SSH Default" --inputs command="yum update -y" --search-query "host_collection_id = 3" --async  > /dev/null 2>&1

If you browse the UI Monitor --> jobs section there should be a new job entry available with all details for every host added in the host collection group.

It took me a while to figure it this all out, highly appreciated any feedback for a better solution!

Hope it helps
Regards
Nic

Responses

Looks pretty good.. I ended up writing a python script that does the raw API work and checks for regular as well as composite content views. and publishes and promotes as needed.

I hear that coming soon to a satellite near you, there will be a publish/promote logic which will do this automatically. So that would eliminate part of the problem, but it would be nice to schedule a content-view publish/promote in the Recurring Logics inside Satellite.

Hi Will, thanks. sounds like an interesting project, do you have a git project online? Yes i agree with you it would be better to have a recurring logic inside the content view section or as a feature available in the job execution.

Unfortunately I do not. I'm part of one of those orgs that limits my ability to contribute upstream or in the open much :/

But I can provide some generalities if you are interested or need a shove in the right direction. Really when you take a look at the API and with a little python or ruby know-how it's pretty simple.. But I also think what you've done above is simple and effective too. It just depends on how much complexity you want/can stand and if you need more flexibility or reporting around your publish/promote activity.

How about doing the same for composite cvs? Any better ideas for automatically updating content views to latest versions under ccvs and publishing/promoting them?

Hi Shisheer, i am in the process to automate CCV as well so below are steps I was thinking to apply:

Click on the CCV and then select "Content views" tab, in the version column select "Latest" this will make sure the latest published version for that particular CV will be used.

example below: CV-RHEL7-BASE | Latest (Currently 5.0) | Library, dev, test, prod

A this point the process should be similar to the one above in the original post. Get a list of CCV and CV by running hammer:

hammer content-view list

Now you can run hammer to trigger the publication and promotion using either CCV name or Content Views ID. Examples:

hammer content-view publish --organization ORG --name 'CCV-NAME' --description 'latest monthly RPMs' --async

#Promote to dev

#select the latest CCV version
LATEST_VERS=`/bin/hammer content-view version list --content-view "CCV-NAME"  --organization ORG |awk '{print $6}'|sort -nr | head -n1`

/bin/hammer content-view version promote --version $LATEST_VERS --organization "ORG" --content-view  'CCV-NAME' --to-lifecycle-environment dev --force --async

Hope it helps

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.