Since we started using the open source cloud platform OpenNebula as our private cloud solution, we struggled to find a simple solution to manage VMs, services and images on it. In the beginning, we had to create instances or manage existing ones manually using the OpenNebula web interface or with some hacky scripts. Because we use Ansible as our main automation platform, we decided to write Ansible modules that will make managing OpenNebula resources a breeze and allow us to make the most of it. Also, given that we’re long-time Ansible users, we wanted to give something back to the community.

After a few months of development and testing, we published: one_vm, one_service, one_image and one_image_facts modules. We’ve also been using them in production for the past 6 months. And the best thing is that these modules will be part of Ansible, starting with version 2.6. This is the first time that Ansible will include OpenNebula modules.

Let me present to you these new modules.

one_vm Module

The module provides the easiest way to manage VM instances in a way to:

  • deploy one or more instances
  • set vm owner, group and permissions
  • terminate, power-off or reboot instances
  • scaling up/down number of instances based on specific attributes and/or labels criteria
  • get instances info

Here are a few examples of how to use the module:

# Create a new instance
- one_vm:
    template_id: 90
  register: result

# Deploy a new VM and set its name to 'foo'
- one_vm:
    template_name: 'app1_template'
    attributes:
      name: foo

# Deploy 2 new instances with label 'bar'
- one_vm:
    template_id: 53
    labels:
      - bar
    count: 2
 
# Deploy 3 new instances and set their names in the format 'foo-##'
# Names will be: foo-00, foo-01 and foo-02
- one_vm:
    template_name: 'app1_template'
    attributes:
      name: foo-##
    count: 3
 
# Enforce that 2 instances with attributes 'foo1: app1' and 'foo2: app2' are deployed
- one_vm:
    template_id: 17
    attributes:
      foo1: app1
      foo2: app2
    exact_count: 2
    count_attributes:
      foo1: app1
      foo2: app2
 
# Reboot all VMs that have label 'bar'
- one_vm:
    labels:
      - bar
    state: rebooted

For more details, check out one_vm documentation.

one_service Module

Provides an easier way to manage OpenNebula services, such as:

  • create a service
  • delete a service
  • set service owner, group and permissions
  • change role cardinality
  • get service info

Here are few examples:

# Instantiate a new service
- one_service:
    template_id: 90
 
# Instantiate a new service with specified service_name, service group and mode
- one_service:
    template_name: 'app1_template'
    service_name: 'app1'
    group_id: 1
    mode: '660'
 
# Delete a service by ID
- one_service:
    service_id: 153
    state: absent

For more details, check out one_service documentation.

one_image Module

Provides an easier way to manage OpenNebula images, such as:

  • clone an image
  • rename an image
  • enable/disable an image
  • delete an image

Here are a few examples of how to use the module:

# Fetch an image info by id
- one_image:
    id: 53
 
# Disable the image by name
- one_image:
    name: 'base-image'
    enabled: no
 
# Rename the image
- one_image:
    id: 34
    state: renamed
    new_name: 'bar-image-1'

For more details, check out one_image documentation.

one_image_facts Module

Provides an easier way to gather facts about images using image’s ids, name or a regex pattern.

# Gather facts about all images
- one_image_facts:
  register: result

# Gather facts about images with IDs
- one_image_facts:
    ids: 
      - 123
      - 456

# Gather facts about an image using the name
- one_image_facts:
    name: 'foo-image'
  register: foo_image

# Gather facts about all IMAGEs whose name matches regex 'app-image-.*'
- one_image_facts:
    name: '~app-image-.*'
  register: app_images

For more details, check out one_image_facts documentation.

We would also like to mention that Ansible 2.6 will also include the one_host module, which is written by Rafael del Valle (with whom we worked to ensure all modules have a similar design).

Do not hesitate to try them out and tell us what you think. Your feedback and contribution will be much appreciated!