Add NFS datastore to cluster

Here is an example of how to use the foreach workflow object.
In this example I am automating the process of adding a NFS datastore to a cluster. Please note that there is no error checking, it will simply try to add the datastore to each host, one or more could fail but the workflow will still complete successfully.

The way the foreach workflow object works is that it will execute another workflow for each object in an array, so you have to break your workflow up in to smaller pieces.

First, there is a workflow that adds a NFS datastore to a single host:


The workflow it self is pretty basic, just a scripted element that adds a NFS datastore.

Likewise, the code to add the NFS datastore is nothing fancy.

Once you have that piece working you can add the workflow that takes a cluster as the input.
Like the previous workflow it is very basic, just a action that returns an array of hosts for the cluster and a foreach object.

The key here is that on the properties of the foreach object you select the loop option on the input that takes the array of hosts.

And that’s it, no more code needed to loop over the array of hosts and execute the workflow for each one of them.

Download package here.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">