Git Product home page Git Product logo

ansible-collection-jm1-libvirt's Introduction

Ansible Collection for using libvirt

This repo hosts the jm1.libvirt Ansible Collection.

The collection includes a variety of Ansible content to help automate the provisioning and maintenance of libvirt clusters.

It is inspired by the Openstack Ansible modules, e.g. jm1.libvirt.domain and jm1.libvirt.volume_cloudinit resemble os_server to create virtual machines with libvirt and cloud-init. For example:

- hosts: all
  tasks:
    - name: Install software required by jm1.libvirt's roles and modules
      import_role:
        name: jm1.libvirt.setup

    - name: Fetch cloud image, create storage volumes and define domain (virtual machine)
      import_role:
        name: jm1.libvirt.server
      vars:
        userdata: |
            #cloud-config
            hostname: {{ inventory_hostname }}

In comparison to the virt_* modules of the community.libvirt Collection, all jm1.libvirt.* modules are idempotent, that is they can be applied multiple times without changing the result beyond the initial application. To create libvirt domains (virtual machines), storage pools or volumes you write virsh-like options in Ansible-idiomatic YAML lists. For example:

- jm1.libvirt.pool
    name: default
    hardware:
        # Commandline arguments of 'virsh pool-define-as' as key-value pairs without
        # the two leading dashs and all other dashs replaced by underscores.
        type: dir
        target: '/var/lib/libvirt/images'

No need to write XML documents as with e.g. virt or virt_pool.

Included content

Click on the name of a module or role to view that content's documentation:

Requirements and Installation

Installing necessary software

Content in this collection requires additional roles and collections, e.g. to collect operating system facts. You can fetch them from Ansible Galaxy using the provided requirements.yml:

ansible-galaxy collection install --requirements-file requirements.yml
ansible-galaxy role install --role-file requirements.yml
# or
make install-requirements

Content in this collection requires additional tools and libraries, e.g. to interact with libvirt's APIs. You can use role jm1.libvirt.setup to install necessary software packages:

- hosts: all
  roles:
    - jm1.libvirt.setup

Or to install these packages locally:

sudo -s

ansible-console localhost << EOF
gather_facts
include_role name=jm1.libvirt.setup
EOF

The exact requirements for every module and role are listed in the corresponding documentation. See the module documentations for the minimal version supported for each module.

Installing the Collection from Ansible Galaxy

Before using the jm1.libvirt collection, you need to install it with the Ansible Galaxy CLI:

ansible-galaxy collection install jm1.libvirt

You can also include it in a requirements.yml file and install it via ansible-galaxy collection install -r requirements.yml, using the format:

---
collections:
  - name: jm1.libvirt
    version: 2022.2.1

Usage and Playbooks

You can either call modules by their Fully Qualified Collection Namespace (FQCN), like jm1.libvirt.domain, or you can call modules by their short name if you list the jm1.libvirt collection in the playbook's collections, like so:

---
- name: Using jm1.libvirt collection
  hosts: localhost

  collections:
    - jm1.libvirt

  tasks:
    - name: Satisfy software requirements
      import_role:
        name: setup

    - name: Create a new libvirt domain with cloud-init
      domain:
        name: 'vm.inf.h-brs.de'

For documentation on how to use individual modules and other content included in this collection, please see the links in the 'Included content' section earlier in this README.

See Ansible Using collections for more details.

Contributing

There are many ways in which you can participate in the project, for example:

  • Submit bugs and feature requests, and help us verify them
  • Submit pull requests for new modules, roles and other content

We're following the general Ansible contributor guidelines; see Ansible Community Guide.

If you want to develop new content for this collection or improve what is already here, the easiest way to work on the collection is to clone this repository (or a fork of it) into one of the configured ANSIBLE_COLLECTIONS_PATHS and work on it there:

  1. Create a directory ansible_collections/jm1;
  2. In there, checkout this repository (or a fork) as libvirt;
  3. Add the directory containing ansible_collections to your ANSIBLE_COLLECTIONS_PATHS.

Helpful tools for developing collections are ansible, ansible-doc, ansible-galaxy, ansible-lint, flake8, make and yamllint.

OS Install Instructions
Debian 10 (Buster) Enable Backports. apt install ansible ansible-doc ansible-lint flake8 make yamllint
Debian 11 (Bullseye) apt install ansible ansible-doc ansible-lint flake8 make yamllint
Red Hat Enterprise Linux (RHEL) 7 / CentOS 7 Enable EPEL. yum install ansible ansible-lint ansible-doc python-flake8 make yamllint
Red Hat Enterprise Linux (RHEL) 8 / CentOS 8 Enable EPEL. yum install ansible ansible-doc python3-flake8 make yamllint
Red Hat Enterprise Linux (RHEL) 9 / CentOS 9 Enable EPEL. yum install ansible ansible-doc python3-flake8 make yamllint
Ubuntu 18.04 LTS (Bionic Beaver) Enable Launchpad PPA Ansible by Ansible, Inc.. apt install ansible ansible-doc ansible-lint flake8 make yamllint
Ubuntu 20.04 LTS (Focal Fossa) apt install ansible ansible-doc ansible-lint flake8 make yamllint

Have a look at the included Makefile for several frequently used commands, to e.g. build and lint a collection.

More Information

License

GNU General Public License v3.0 or later

See LICENSE.md to see the full text.

Author

Jakob Meng @jm1 (github, galaxy, web)

ansible-collection-jm1-libvirt's People

Contributors

jm1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.