A Playbook is a collection of tasks that can be executed based on a trigger, such as a time, a webhook, or a manual action. A Playbook can be used to automate workflows across different systems and services, such as Nutanix Prism, VMs, hosts, and external APIs. A Playbook can also use variables, conditions, and loops to customize the execution logic and data.
In this scenario, the administrator wants to automate the batch processing application on the Linux VM, which can only be controlled by a command on the VM console. The application should run only outside of business hours, and the VM should send REST API calls to Prism to report its status.
The best way to configure a Playbook for this process is to use a Time Trigger, which allows the administrator to specify a schedule for the Playbook execution, such as daily, weekly, or monthly. The Time Trigger can also be configured to run only on certain days or hours, such as weekdays or nights. This way, the administrator can ensure that the Playbook runs only outside of business hours, without requiring any manual intervention.
The Playbook should then have two VM SSH tasks, one to initiate the batch processing application, and one to terminate it. A VM SSH task is a task that executes a command or script on a target VM using SSH. A VM SSH task can be used to control applications or services that do not have a programmatic interface, such as the batch processing application in this scenario. The VM SSH task can also use variables to pass data to or from the command or script, such as the VM name, IP address, or output.
The Playbook should also have a Wait for Some Time task, which is a task that pauses the Playbook execution for a specified duration or until a condition is met. A Wait for Some Time task can be used to ensure that the batch processing application has enough time to complete its work, or to wait for a certain event or state to occur, such as a file creation, a service status, or a VM power state.
The Playbook should also have two REST API tasks, one before and one after the Wait for Some Time task. A REST API task is a task that executes an HTTP request to a specified URL, with optional headers, body, and authentication. A REST API task can be used to interact with external systems or services that expose an API, such as Nutanix Prism in this scenario. The REST API task can also use variables to pass data to or from the HTTP request, such as the VM name, IP address, or response.
The REST API tasks should be configured to send the VM status to Prism, such as the start and end time of the batch processing, the CPU and memory usage, or the output of the application. This way, the administrator can monitor and manage the VM and the application from Prism, without having to connect to the VM console.
The Playbook configuration should look something like this:
Time Trigger: Set the schedule to run daily, only on weekdays, and only at night (e.g., 10 PM to 6 AM).
VM SSH: Set the target VM to the Linux VM, and set the command or script to initiate the batch processing application (e.g., ./batch.sh start).
REST API: Set the URL to the Prism API endpoint, and set the HTTP method, headers, body, and authentication as required. Use variables to pass the VM name, IP address, and start time of the batch processing to the HTTP request (e.g., {"vm_name": "{{vm_name}}", "vm_ip": "{{vm_ip}}", "start_time": "{{start_time}}"}).
Wait for Some Time: Set the duration to the expected time for the batch processing to finish, or set a condition to wait until a certain event or state occurs (e.g., wait until file /tmp/batch.done exists).
REST API: Set the URL to the Prism API endpoint, and set the HTTP method, headers, body, and authentication as required. Use variables to pass the VM name, IP address, end time, and output of the batch processing to the HTTP request (e.g., {"vm_name": "{{vm_name}}", "vm_ip": "{{vm_ip}}", "end_time": "{{end_time}}", "output": "{{output}}"}).
VM SSH: Set the target VM to the Linux VM, and set the command or script to terminate the batch processing application (e.g., ./batch.sh stop).
References:
https://www.nutanix.com/content/dam/nutanix/resources/datasheets/ds-ncp-mca-6-5.pdf
https://www.nutanix.com/content/dam/nutanix/resources/support/ds-ncp-mca.pdf