Ansible is a popular open-source automation and orchestration tool. The Morpheus platform natively integrates with the open-source Ansible engine as well as the Ansible Automation controller (formerly known as Ansible Tower). The 5.4.3 release of the Morpheus platform includes several enhancements to the Ansible integration.
This release adds the ability to pass Morpheus variables to a playbook without the need to define the Morpheus variables in the Ansible playbook itself. This makes working with Ansible playbooks a simpler and more consistent experience when developing and testing playbooks from a local machine. If we look at the following example we can see how simple it is to use this feature. The playbook expects a variable for the MongoDB version.
---
- hosts: all
gather_facts: true
tasks:
- name: Include the mongodb role
include_role:
name: mongodb
vars:
mongodb_version: "{{ mongodb_version }}"
The ansible-playbook command supports defining variables at the command line. To use this feature the --extra-vars
flag is added to the COMMAND OPTIONS field in the Ansible playbook task with the variables defined as key value pairs (key=value). The value of the Ansible variable is the Morpheus input/option using the Morpheus Ansible variable format. In this case we’ve created an input or option type in the Morpheus platform with the field name mongodb_version.
--extra-vars "mongodb_version={{ morpheus['customOptions']['mongodb_version'] }}"
The Morpheus Ansible integration supports dynamically fetching Ansible code from source control. The code is fetched from source control prior to every playbook execution to ensure the latest code is used. This works well in most situations, but there are scenarios where the constant polling of the source control system creates an issue. This where the git repository caching feature becomes useful. Morpheus will cache the repository for a default period of 5 minutes and will check for new code once the cache has expired.
Enable git repository caching on an Ansible integration by checking the ENABLE GIT REPOSITORY CACHING checkbox.
Ansible collections are the new Ansible content packaging format introduced in Ansible engine 2.9. A collection can include playbooks, roles, modules, and plugins. The 5.4.3 release of the Morpheus platform adds native support for installing Ansible collections. Add the collection to the requirements.yml dependency file in the git repository to use a collection. The example below displays adding a role as well as a collection via the requirements.yml dependency file.
---
roles:
# Install a role from Ansible Galaxy.
- name: geerlingguy.java
version: 1.9.6
collections:
# Install a collection from Ansible Galaxy.
- name: geerlingguy.php_roles
version: 0.9.3
source: https://galaxy.ansible.com
The Ansible integration in the Morpheus platform enables organizations to execute Ansible playbooks at scale. And, the 5.4.3 release of the Morpheus platform improves upon this capability with the addition of variable injection, git repository caching, and collections support.
Try Morpheus Community Edition or Get a Demo
The Morpheus Community Edition lets you fully experience the Morpheus platform including nearly all features and capabilities! Register at Morpheus Hub and try it in your home lab or test environment today! Interested in learning more about Morpheus from one of our cloud transformation experts? Schedule a demo to walk through how Morpheus can help your organization here.