Many companies today are leveraging new tools to automate deployments and handle configuration management. Ansible is a great tool that offers flexibility when creating and managing your environments.
SoftLayer has components built within the Ansible codebase, which means continued support for new features as the Ansible project expands. You can conveniently pull your SoftLayer inventory and work with your chosen virtual servers using the Core Ansible Library along with the SoftLayer Inventory Module. Within your inventory list, your virtual servers are grouped by various traits, such as “all virtual servers with 32GB of RAM,” or “all virtual servers with a domain name of softlayer.com.” The inventory list provides different categorized groups that can be expanded upon. With the latest updates to the SoftLayer Inventory Module, you can now get a list of virtual servers by tags, as well as work with private virtual servers. You can then use each of the categories provided by the inventory list within your playbooks.
So, how can you work with the new categories (such as tags) if you don’t yet have any inventory or a deployed infrastructure within SoftLayer? You can use the new SoftLayer module that’s been added to the Ansible Extras Project. This module provides the ability to provision virtual servers within a playbook. All you have to do is supply the build detail information for your virtual server(s) within your playbook and go.
Let’s look at an example playbook. You’ll want to specify a hostname along with a domain name when defining the parameters for your virtual server(s). The hostname can have an incremental number appended at the end of it if you’re provisioning more than one virtual server; e.g., Hostname-1, Hostname-2, and so on. You just need to specify a value
True for the parameter increment. Incremental naming offers the ability to uniquely name virtual servers within your playbook, but is also optional in the case where you want similar hostnames. Notice that you can also specify tags for your virtual servers, which is handy when working with your inventory in future playbooks.
Following is a sample playbook for building Ubuntu virtual servers on SoftLayer:
--- - name: Build Tomcat Servers hosts: localhost gather_facts: False tasks: - name: Build Servers local_action: module: softlayer quantity: 2 increment: True hostname: www domain: test.com datacenter: mex01 tag: tomcat-test hourly: True private: False dedicated: False local_disk: True cpus: 1 memory: 1024 disks:  os_code: UBUNTU_LATEST ssh_keys: 
By default, your playbook will pause until each of your virtual servers completes provisioning before moving onto the next plays within your playbook. You can specify the
wait parameter to
False if you choose not to wait for the virtual servers to complete provisioning. The
wait parameter is helpful for when you want to build many virtual servers, but some have different characteristics such as RAM or tag naming. You can also set the maximum time you want to wait on the virtual servers by setting the
wait_timeout parameter, which takes an integer defining the number of seconds to wait.
Once you’re finished using your virtual servers, canceling them is as easy as creating them. Just specify a new playbook step with a state of
absent, as well as specifying the virtual server ID or tags to know which virtual servers to cancel.
The following example will cancel all virtual servers on the account with a tag of
- name: Cancel Servers hosts: localhost gather_facts: False tasks: - name: Cancel by tag local_action: module: softlayer state: absent tag: tomcat-test
New features are being developed with the core inventory library to bring additional functionality to Ansible on SoftLayer. These new developments can be found by following the Core Ansible Project hosted on Github. You can also follow the Ansible Extras Project for updates to the SoftLayer module.
As of this blog post, the new SoftLayer module is still pending inclusion into the Ansible Extras Project. Click here to check out the current pull request for the latest code and samples.