Starting with CloudForms 4.6, we can make custom buttons visible if certain requirements are met. We can also make the button active or inactive as needed. Both features significantly improve the user experience by simplifying the interface and making it more dynamic.
The Enablement expression is validated to enable or disable the button based on the specified check. This allows you to enable the button only if some specific requirements are met. In the example below, we want to run an Ansible Playbook inside the VM. The expression validates the VM Power State and the button will be disabled if the VM is not powered on. An additional text will inform the user why the button is disabled and how to solve the issue.
The Visibility allows you to define an expression which is validated to decide if the button should be shown at all. For example, if the guest Operating System is not Linux, the Ansible Playbook used will not work. If CloudForms detects a non-Linux VM, the menu will not be shown at all.
Note that the visibility settings on the bottom of the dialog are the same as in previous versions. This option allows us to make the button only available for certain user roles, for example administrators, operators or normal users.
Let’s configure an regular expression which verifies the Virtual Machine is powered on.
Navigate to Automation -> Automate -> Customization
You should already be in this menu if you followed the previous steps
Click on the “Install Package” Button you created in the previous lab
Click on Configuration -> Edit this Button
Click on the Advanced tab
Click on Expression
Build the following Expression:
Field: VM and Instance - Power State = on
Don’t forget to click on the check mark to save the expression!
Add Disabled Button Text: VM must be powered on to run Ansible Playbook
Click Save
The install package Playbook will only work on RHEL 7 Virtual Machines. It will fail on RHEL 6 Virtual Machines, because the lab internal YUM mirror does not have a copy of the relevant channels.
Since this is a known limitation, it is a good idea to not show the button if the guest Operating System of the selected Virtual Machine does not meet the requirements. With the new “Visibility” expression filter, this is easy to implement.
Navigate to Automation -> Automate -> Customization
You should already be in this menu if you followed the previous steps
Click on the “Tools” Button Group you created in the previous lab
Click on Configuration -> Edit this Button
Click on the Advanced tab
in the Visibility section of the dialog, create the following expression:
Field: VM and Instance.OS: Product Name - STARTS WITH "rhel_7"
Don’t forget to click on the check mark to save the expression!
Click Save
The automatically generated Service Dialog is not perfect. It might confuse the user with too many input fields. It asks for the “Machine Credentials”, but those have already been defined in the Service Catalog Item. It also asks for the “Host”, but this one is automatically adjusted to be the selected Virtual Machine. And finally the field “package_name” could benefit from a more descriptive text.
In the following steps, we want to make the Service Dialog more user friendly by simplifying it.
Navigate to Automation -> Automate -> Customization
Click on Service Dialogs in the accordion on the left
Click the check box next to “InstallPackage”
Click on Configuration -> Copy the selected Dialog to a new Dialog
Let’s improve the Service Dialog by applying the following changes:
Dialog’s name: Install Package from Button
Hide the element “Machine Credentials” by clicking on the little pen icon.
The edit icon only shows if you move the mouse pointer over the “Machine Credentials” text box.
Do not delete the element, only hide it! The element is still needed for some CloudForms internal logic and should not be removed.
Click on Overridable Options and switch the Visible switch to “No”
Click Save to close the dialog
Repeat this for the “Hosts” element. Click on the pen icon next to it.
The edit icon only shows if you move the mouse pointer over the “Hosts” text box.
Click on Options and switch Visible to “No”
Do not delete the element, only hide it! The element is still needed for some CloudForms internal logic and should not be removed.
Click on the little pen icon next to the “package_name” text box
The edit icon only shows if you move the mouse pointer over the “package_name” text box.
Change the label to something more descriptive:
Label: Enter Package Name
Do not change the field “Name” - it is the name of the variable used internally by CLoudForms and the Ansible Playbook. if you change the name of this field, the Playbook will not pickup the new variable and hence ignore the user input.
Also let’s give more information to the user by improving the “Help” text:
Help: Enter the name of the RPM package to be installed on the system
Click Save to apply the changes
Click Save To save all changes we made in the Service Dialog
This concludes this part of the lab.
To be able to use the new Service Dialog with our button, we first have to create an additional Service Catalog Item, which points to the Service Dialog.
Navigate to Services -> Catalogs
Navigate to Catalog Items in the accordion on the left
Click on Configuration -> Add a New Catalog Item
Select Ansible Playbook as Catalog Item Type
Use the following parameters when defining the Service Catalog Item:
Name: Install Package from Button
Description: Install Package via Ansible Playbook
Display in Catalog: Yes
Catalog: Ansible
Repository: Github
Playbook: playbooks/InstallPackage.yml
Machine Credentials: Virtual Machine credentials
Variables & Default Values: add one new entry with:
Variable: package_name
Default Value: httpd
Click the little plus ("+") icon to save the row.
Dialog: Use Exiting
Use “Install Package from Button” as the name of the Dialog, which is the one we created in the step before.
Click Add to save all changes
As the last step, we have to change the definition of our button, to point to the just created Service Catalog Item.
Navigate to Automation -> Automate -> Customization
Click on Buttons in the accordion on the left
Click on the “Install Package” Button you created in the previous lab
Click on Configuration -> Edit this Button
Change the Playbook Catalog item to the new one you just created “Install Package from Button”
Click Save to store all changes
Navigate to Compute -> Infrastructure -> Virtual Machines
Click on the “cfme001” tile if not already selected
On the details page of “cfme001” click on Tools -> Install Package
Click on Tools -> Install Package
You should see the simplified version of the Dialog. The Package Name has a better description, there is a tool tip if you hover the mouse over the little “i” icon and the redundant fields for “Machine Credentials” and “Hosts” are gone.
Click Submit to execute the Button action
Navigate to Services -> My Services
As a result of your action, a new “My Services” object was created. If you don’t see it yet, wait a minute and click on the reload button.
Click on the “Install Playbook” item to see the details
Click on the Provisioning tab to see output from your Ansible Playbook
This concludes this part of the Ansible lab.
Feel free to repeat this part of the lab with a different package name. You could use “screen” as an example instead of httpd - or some other package you want to install.