Publish and promote content views automatically for system patching
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.
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.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
