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.


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. 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.


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


  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:


    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/ 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.


  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 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.


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


  1. Create your playbook.

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

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