3.5. Automating Configuration Tasks using Ansible


Ansible is an automation tool used to configure systems, deploy software, and perform rolling updates. Red Hat Virtualization includes a limited version of Ansible to automate RHV post-installation tasks such as data center setup and configuration, managing users, and virtual machine operations.

Ansible provides an easier method of automating Red Hat Virtualization configuration compared to REST APIs and SDKs, and you can integrate with other Ansible modules. For more information about the Ansible modules available for Red Hat Virtualization, see the oVirt Ansible Collection in the Red Hat Ansible Automation Hub documentation.

Note

Ansible Tower is a graphically enabled framework accessible through a web interface and REST APIs for Ansible. If you want support for Ansible Tower, then you must have an Ansible Tower license, which is not part of the Red Hat Virtualization subscription.

See the Ansible documentation for alternate installation instructions, and information about using Ansible.

3.5.1. oVirt Ansible Collection

oVirt Ansible Collection provides modules, roles, and plugins for managing various parts of the Red Hat Virtualization infrastructure. The modules are used for communication between Ansible and the Red Hat Virtualization Manager. Ansible roles provide a method of modularizing Ansible code by breaking up large playbooks into smaller reusable files that can be shared with other users. For more information about oVirt Ansible Collection, see the Automation Hub documentation.

3.5.1.1. Installing oVirt Ansible Collection from an RPM package

You can install oVirt Ansible Collection for Red Hat Virtualization from the Red Hat Virtualization Manager repository.

Prerequisites

To install oVirt Ansible Collection, you must subscribe to one of the following subscription channels:

  • Using a Red Hat Virtualization subscription - rhv-4.4-manager-for-rhel-8-x86_64-rpms
  • Using any Red Hat Enterprise Linux subscription - rhv-4-tools-for-rhel-8-x86_64-rpms

Procedure

  1. Run the following command to install the oVirt Ansible Collection on the Manager machine:

    # dnf install ovirt-ansible-collection
  2. By default, the collection is installed to:

    /usr/share/ansible/collections/ansible_collections/redhat/rhv.

    The structure of the ovirt-ansible-collection package is as follows:

    /usr/share/ansible/collections/ansible_collections/redhat/rhv/usr/share/doc/ovirt-ansible-collection/

3.5.1.2. Installing oVirt Ansible Collection from Automation Hub

Automation Hub is a new place that can be used to install oVirt Ansible Collection. To configure the environment, follow the instructions in oVirt Ansible Collection documentation.

Procedure

  1. Install the collection

    # ansible-galaxy collection install redhat.rhv
  2. The Automation Hub currently does not install RPM dependencies. Make sure that you have these packages on the host where you execute the playbook:

    • python3-ovirt-engine-sdk4
    • python3-netaddr
    • python3-jmespath
    • python3-passlib

3.5.1.3. Using oVirt Ansible Collection to Configure Red Hat Virtualization

The following procedure guides you through creating and running a playbook that uses oVirt Ansible Collection to configure Red Hat Virtualization. This example uses Ansible to connect to the Manager on the local machine and create a new data center.

Prerequisites

  • Ensure that you have the Python SDK installed on the machine running the playbook.

Procedure

  1. Create your playbook.

    - name: RHV infrastructure
      hosts: localhost
      connection: local
      gather_facts: false
    
      vars_files:
       # Contains variables to connect to the Manager
       - engine_vars.yml
       # Contains encrypted engine_password variable using ansible-vault
       - passwords.yml
    
      pre_tasks:
       # The use of redhat.rhv before ovirt_auth is to check if oVirt Ansible Collection is correctly loaded
       - name: Login to RHV
         redhat.rhv.ovirt_auth:
           hostname: "{{ engine_fqdn }}"
           username: "{{ engine_user }}"
           password: "{{ engine_password }}"
           ca_file: "{{ engine_cafile | default(omit) }}"
           insecure: "{{ engine_insecure | default(true) }}"
         tags:
           - always
    
     vars:
       data_center_name: mydatacenter
       data_center_description: mydatacenter
       data_center_local: false
       compatibility_version: 4.4
    
     roles:
       - infra
     collections:
       - redhat.rhv
     post_tasks:
       - name: Logout from RHV
         ovirt_auth:
           state: absent
           ovirt_auth: "{{ ovirt_auth }}"
         tags:
           - always

You have successfully used the infra Ansible role from oVirt Ansible Collection to create a data center named mydatacenter.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.