SEARCH
TOOLBOX
LANGUAGES
Python

Python

From GarrettHoneycutt

Jump to: navigation, search

Sample code

The following is a piece of python I used in conjunction with Cobbler which allows me to run a script when I add a system that will pre-generate puppet certs.

Posted to RedHat's et-mgmt-tools mailing list in April 2008

getcert.trigger

#!/usr/bin/python
 
import os
import sys
 
from cobbler import api
cobbler_api = api.BootAPI()
 
 
# this is the systemname, not the hostname, so be sure to use the FQDN in the systemname
 
machine = sys.argv[1]
 
# location of getcert.sh script
getcert_cmd = "/usr/local/sbin/getcert.sh"
 
# set return code to 0 by default
rc = 0
 
# build the command string
cmd = getcert_cmd + " " + machine
 
# log to cobbler's logs
cobbler_api.log("running - " + cmd)
 
# run the command and set the return code
rc = os.system(cmd)
 
# exit with return code
sys.exit(rc)

Cheat Sheet

Image:Python-cheat-sheet-v1.png