Automation is a key enabler of the digital transformation initiatives that organizations of all sizes have embarked upon the last few years. Automation is also a great force multiplier but is less effective when the automation builders are also the automation executors. As the adoption of automation has continued to grow, the need for scaling that automation beyond Centers of Excellence (CoE) or those well versed in the automation tools grows as well. Enterprise organizations have adopted Puppet Enterprise to meet their automation needs. Puppet Enterprise supports the execution of ad-hoc automation tasks. This complements the agent based configuration management that the platform has become known for. In this blog post we’ll walk through how to trigger a Puppet Enterprise automation task through the Morpheus self-service portal.
The goal of this solution is to empower individuals in enterprise organizations to self serve automation via the Morpheus service catalog. This post assumes that the Puppet Enterprise server is running a version that supports tasks and nodes have been added to the inventory.
The following high level steps are how the solution will work:
The first thing we’ll do is create the inputs that the requestor will be prompted to fill in.
Package Name | Package Action | Puppet Environment | Puppet Targets | |
---|---|---|---|---|
Name | Puppet Package Name | Puppet Package Action | Puppet Environment | Puppet Targets |
Field Name | packageName | packageAction | puppetEnvironment | puppetTargets |
Type | Text | Select | Text | Typeahead |
Label | Package Name | Action | Puppet Environment | Targets |
Option List | N/A | Puppet Package Actions | N/A | Puppet Targets |
We’ll use option lists for the package action and the Puppet Enterprise target nodes. The package action will use a manual list with static entries and the puppet targets list will query the Puppet Enterprise REST API for the target nodes. The Puppet Enterprise REST API call is against an authenticated endpoint and requires a Puppet Enterprise token for authentication.
Puppet Package Actions | Puppet Targets | |
---|---|---|
Name | Puppet Package Actions | Puppet Targets |
Type | Manual | REST API |
Data Set | [ {“name”: “Install”, “value”: “install”}, {“name”:”Status”,”value”:”status”}, {“name”:”Uninstall”,”value”:”uninstall”}, {“name”:”Upgrade”,”value”:”upgrade”} ] | N/A |
Source URL | N/A | https://peserver.morpheusdata.com:8143/orchestrator/v1/inventory |
Source Method | N/A | GET |
Source Headers | N/A | Content-Type: application/json X-Authentication: PE_TOKEN |
Translation Script | N/A | inputData = data.items for(var x=0;x < inputData.length; x++) { print(inputData[x]) results.push({name: inputData[x].name, value:inputData[x].name}); } |
Before we create our Python script we’ll store the Puppet Enterprise token in Morpheus Cypher to easily access it from our Python script.
The core of the integration is the REST API call to the Puppet Enterprise server. In this case we’ll create a Morpheus python script task to interact with the Puppet Enterprise orchestrator API endpoint.
import requests
import time
from morpheuscypher import Cypher
urllib3.disable_warnings()
url = 'https://peserver.morpheusdata.com:8143/orchestrator/v1/command/task'
token = Cypher(morpheus=morpheus,ssl_verify=False).get('secret/petoken')
headers = {'X-Authentication': token, "Content-Type": "application/json"}
instances = []
if type(morpheus['customOptions']['puppetTargets']).__name__ == 'list':
for vm in morpheus['customOptions']['puppetTargets']:
instances.append(vm)
else:
instances = [morpheus['customOptions']['puppetTargets']]
payload = {}
payload['environment'] = morpheus['customOptions']['puppetEnvironment']
payload['task'] = "package"
payload['params'] = {}
payload['params']['action'] = morpheus['customOptions']['packageAction']
payload['params']['name'] = morpheus['customOptions']['packageName']
payload['scope'] = {}
payload['scope']['nodes'] = instances
r = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)
jsonResponse = r.json()
time.sleep(10)
jobDetails = requests.get(jsonResponse['job']['id'] + '/nodes', headers=headers, verify=False)
jobResponse = jobDetails.json()
for item in jobResponse['items']:
print("Name: " + item['name'])
print("Duration: " + str(item['duration']))
print("State: " + item['state'])
print("Result: " + str(item['result']))
Now that we’ve got our automation task, we need to create an operational workflow in Morpheus. The workflow enables us to associate inputs or option types with the automation task. It also allows us to create a catalog item in the self-service catalog. We’ll add the task we created in the previous step along with the inputs or option types.
At this point we can trigger the workflow without a catalog item but we want to simplify the request process by creating a service catalog item. In this example we’ve created a catalog item that includes the custom options created earlier.
Once the catalog item has been ordered the results of the task execution will be made available in the catalog inventory to review.
In this blog post we looked at how to run Puppet Enterprise tasks in a self-service fashion using the Morpheus self-service catalog. This enables IT teams to scale their automation across the organization and empower other teams to consume automation at the push of a button.
Try Morpheus Community Edition or Get a Demo
The Morpheus Community Edition lets you fully experience the Morpheus platform including nearly all features and capabilities! Register at Morpheus Hub and try it in your home lab or test environment today! Interested in learning more about Morpheus from one of our cloud transformation experts? Schedule a demo to walk through how Morpheus can help your organization here.