Calling a Playbook Method from the VM Provision State Machine
Last updated
Last updated
Given the ability to run embedded Ansible playbooks as methods, it can be useful to include such a playbook into an existing workflow such as the VM Provision state machine.
In this example an Ansible playbook method is used at the AcquireIPAddress state to insert an IP address, netmask and gateway into the VM provisioning workflow. A cloud-init script is then used at first boot to set the values in the new VM using nmcli
.
A new acquire_ip_address instance and method are defined in the usual manner. The method is of Type: playbook and is defined to run on Hosts: localhost (see screenshot acquire_ip_address Instance and Method).
The input parameters for the playbook method are dynamic. Two parameters miq_provision_request_id
(the request ID) and miq_provision_id
(the task ID), are defined for the method (see screenshot Input Parameters).
The new instance is added to the AcquireIPAddress state of the VM Provision state machine (see screenshot Instance Added to the VM Provision State Machine).
The playbook can write the acquired IP details back into the provision task's options hash in either of two ways: using the RESTful API, or using the manageiq-vmdb Ansible role (see section manageiq-vmdb).
The first example playbook uses the CloudForms RESTful API to write the retrieved IP details back in to the provision task's options hash. To simplify the example the IP address, netmask and gateway are defined as static vars; in reality these would be retrieved from a corporate IPAM solution such as Infoblox.
The second example playbook uses the manageiq-vmdb Ansible role to write the retrieved IP details back into the provision task's options hash. Once again the IP address, netmask and gateway are defined as static vars for simplicity of illustration.
In these example playbooks the netmask variable is defined in CIDR format rather than as octets, to be compatible with nmcli
.
Configuring a NIC with IP address details is a guest operating system operation, and so must be performed when the VM or instance first boots. For this example a template cloud-init script is defined in Compute -> Infrastructure -> PXE -> Customization Templates in the CloudForms WebUI, as follows:
If the cloud-init script is selected from the Customize tab of the provisioning dialog, CloudForms will make the variable substitutions at run-time and inject the resultant script into the VM or instance to be run at first boot.