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