The previous two articles covered how vRealize Automation 8 works with Ansible Open Source. Our infrastructure already uses Polemarch to work with Ansible, but there is no integration with it in vRA 8. In order not to wait for the development of integration from VMware, we will do it ourselves using Custom Resources and Dynamic Types.
Polemarch is an Ansible based infrastructure management system with a simple web interface and API. Polemarch is focused on essential functionality – it is the Spartan competitor to Ansible Tower.
VRA Integration Pack – Polemarch
v1.0.0
This version implements the basic processes for working with Polemarch objects, as well as processes for integrating with vRA, including:
- creation and customization of inventories;
- passing custom variables;
- setting a list of playbooks and launching them after deploying a VM;
- setting a list of playbooks and launching them before deleting a VM.
vRA. Custom Resource
If in vRA 7 any process from the orchestrator could be published as XaaS and used to create blueprints, in vRA 8 this is no longer the case (current version 8.1). From the vRA portal, you can still grant access to any process, this is configured in Service Broker. And to use workflow as part of blueprints, you need to create a Custom Resource. This is a powerful tool, with the help of it you can significantly expand the functionality of blueprints, since you will not be limited to a set of vRA types. For a new Custom Resource, you need to specify the type of object to create. Two options are considered correct: developing a new type in the Plug-in SDK, or creating your own DynamicTypes. For the second, you do not need to be an advanced programmer, and its functionality is sufficient for most tasks.
This integration pack includes DynamicTypes: Polemarch.Playbook and all necessary processes. From the point of view of Polemarch, it was more correct to call this type Inventory and not Playbook, because a dedicated inventory is created for each such object, hosts and user variables are registered in it. After creating all objects, playbooks from the provision list are launched for execution . If the de_provision list does not contain playbooks, then the inverter is immediately deleted so that a bunch of old objects does not accumulate in the vRO (you can not delete the inverter in Polemarch, the filter by the variable is used in the request for the inventory list: variables = active: true , just set it to false). Custom Resource is created for DynamicTypes: Polemarch.Playbook (see screenshot on the right).
vRA. Blueprints
The input parameters of the “Start provision playbooks” process (this process is specified when creating the Custom Resource in the Lifecycle Actions – Create field) will be available as editable fields after adding our resource to the blueprint.
An example of a blueprint with one virtual machine:
formatVersion: 1 name: Polemarch SingleVM version: 1 inputs: {} resources: Config_VM: type: Custom.Polemarch.Playbook dependsOn: - VM properties: hosts: '${resource.VM.address}' inventoryName: 'vRA_${env.deploymentId}' playbooks: - provision: - centod_config.yml hostVariables: | deploy_server: true server_type: vRA env_type: test VM: type: Cloud.Machine properties: image: CentOS_7 flavor: small customizationSpec: tmp-linux-vra networks: - network: '${resource.vSphere_Network.id}' assignment: static vSphere_Network: type: Cloud.vSphere.Network properties: networkType: existing
An example of a blueprint with several virtual machines and two Custom Resource:
formatVersion: 1 name: Polemarch MultiVM version: 1 inputs: {} resources: Install_App: type: Custom.Polemarch.Playbook dependsOn: - App_VMs - Install_DB properties: hosts: '${join(resource.App_VMs.address, ",")}' inventoryName: '${join(["vRA", env.deploymentId, "app"], "_")}' playbooks: - provision: - centos_config.yml - soft_install.yml hostVariables: | deploy_server: true server_type: vRA env_type: test install_tomcat: true Install_DB: type: Custom.Polemarch.Playbook dependsOn: - DB_VMs properties: hosts: '${resource.DB_VMs.address}' inventoryName: '${join(["vRA", env.deploymentId, "db"], "_")}' playbooks: - provision: - centos_config.yml - soft_install.yml de_provision: - db_backup.yml hostVariables: | deploy_server: true server_type: vRA env_type: test install_postgresql: true pg_version: 12 App_VMs: type: Cloud.Machine properties: count: 3 image: CentOS_7 flavor: small customizationSpec: tmp-linux-vra networks: - network: '${resource.vSphere_Network.id}' assignment: static DB_VMs: type: Cloud.Machine properties: image: CentOS_7 flavor: medium customizationSpec: tmp-linux-vra networks: - network: '${resource.vSphere_Network.id}' assignment: static vSphere_Network: type: Cloud.vSphere.Network properties: networkType: existing
The blueprint code is available at https://github.com/isas2/vra.
Preparing the package for work
1. Install the package into vRealize Orchestrator:
- Download the vRO package ru.zabedu.polemarch.package;
- ATTENTION! You do NOT need to import the ru.zabedu.polemarch.package package through the Packages tab, it contains DynamicTypes settings that will not be applied during import;
- Go to the Workflows tab, Library-> the Dynamic Types-> the Configuration , start the process of «Import Configuration From Package» and in the Select the file «ru.zabedu.polemarch.package»;
- Make sure all items have been successfully imported: processes, actions, config items, new DynamicTypes.
2. Run the Initialize process, which will:
- Registering REST host – “ Add Polemarch REST host “ and saving the link to the host in the polemarchConfig configuration element;
- Launching the registration process of the used REST operations: “Add Polemarch REST operations”;
- Obtaining and saving the Polemarch token: “New token”;
- Saving in the configuration element polemarchConfig the ID of the main project in Polemarch and the name of the remote user for accessing virtual machines.
- Project and user names can be specified in the blueprint, but if specified in the configuration item, they can be omitted in the blueprints.
3. Create Custom Resource and Blueprints in vRA:
- Create a new Custom Resource for DynamicTypes: Polemarch.Playbook;
- Create and customize blueprints.
Translated by Google Translate