GithubHelp home page GithubHelp logo

hozgan / ansible-role-qcow2builder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thisdwhitley/ansible-role-qcow2builder

0.0 0.0 0.0 7 KB

This role will provision a VM on your libvirt environment. It requires an qcow2 KVM image and various variables.

License: MIT License

ansible-role-qcow2builder's Introduction

Ansible Role: QCOW2builder

Red Hat and the open source community provide an optimized image for virtualization. This is can be downloaded from Red Hat as a compressed qcow2 image. These have a title such as "Red Hat Enterprise Linux X.x KVM Guest Image" and are typically much smaller than a full Binary DVD download. Because of this, this role will utilize the smaller size, make some modifications and create a VM based on passed parameters.

I prefer to pass the variables "into" the role from the playbook versus by includeing variable files. This is because I hope to make the role usable by other roles. I don't know if this logic makes sense or not, but I am essentially attempting to remove the variables from the role itself. (Maybe I should at least include defaults that simply don't work? I think that if I put them in a file in the repo, then others will assume that is where they should go and that is not my intention.)

At a high level, this role does the following:

  1. Create a copy of the already-downloaded qcow2 image to work on
  2. Install some requisite packages on the Ansible host (we'll be utilizing delegate_to quite a bit)
  3. Make some changes prior to creating the VM from this image to include:
    1. Remove cloud-init (we won't be using that and it causes the VM to take forever to boot)
    2. Inject an SSH key of the user using this role
  4. Use virt-install to create the VM with all the specified configurations and by using the supplied qcow2 image as the boot disk

The result is a freshly built and running VM. The longterm vision is that this role will be used in other roles...and to this end, the role will add the new VM to an inventory group named allVMs.

Important Notes

  • This could be changed to prompt for a password to use for root and insert that into the image, but using keys avoids the need to modify sshd_config

    virt-customize -a $IMAGE --root-password password:pASSword!
    
  • This is currently developed to be used on a system locally. In order to use it with Tower or AWX will take some refactoring

  • This role is far from idempotent at this point. During testing I have found the following commands helpful to clean up:

    sudo virsh destroy <vm.name>;
    sudo virsh undefine <vm.name> --remove-all-storage
    
  • The role will add the newly created VM into a group named allVMs which is cool because subsequent plays can then use hosts: allVMs and it will act on the VM created in this role. Bingo bango.

Requirements

I couldn't escape a few requirements:

  • You'll need to have your libvirt environment configured to your liking. I'm working on creating my own preferences in a separate role...to be continued...
  • A locally downloaded KVM qcow2 image of the distribution you wish to install
  • Because I inject the ssh key of the user calling ansible, you will need to ensure that you have created a key locally and actually that it is called ~/.ssh/id_rsa.pub

Role Variables

All of these variables should be considered required however, just know that there is currently no sanity checking:

  • vm I've created a bit of a nested list here so that the variables can be used like vm.name
    • name
      • the hostname of the new VM
    • os_type this could probably be hard coded since it will always be Linux
    • os_variant this will be specific to what image you're using. the way to find acceptable values varies, but I used osinfo-query os
    • network another layer, but with the idea that I could add IP info, etc
      • name
        • the libvirt network the VM will be on
  • qcow2
    • name
      • the filename of the qcow2 KVM image to be used
    • location
      • the absolute path to the image to be used this is local to the system calling the playbook

Example Playbook

Playbook with configuration options specified and utilizing the allVMs group for a subsequent play:

- hosts: localhost
  connection: local
  roles:
    - role: QCOW2builder
      vm:
#        name: rhel69
        name: rhel74
        memory: 2048
        os_type: Linux
#        os_variant: rhel6.9
        os_variant: rhel7.4
        network:
          name: default # this is the libvirt network the vm will be on
      qcow2:
#        name: rhel-server-6.9-update-9-x86_64-kvm.qcow2
        name: rhel-server-7.4-update-4-x86_64-kvm.qcow2
        location: /depot/images/libvirt/ # this must be local

- hosts: allVMs
  roles:
    - role: do_something_to_the_VM_just_created

Inclusion

  • I'm imagining this role as a part of other roles, such as to create a Satellite server. So I have included a fairly generic meta/main.yml file which allows for something similar to:

      ansible-galaxy install -p ./roles -r requirements.yml
    

    with requirements.yml containing:

      ---
      # get the QCOW2builder role from github
      - src: https://github.com/dswhitley/ansible-role-QCOW2builder.git
        scm: git
        name: QCOW2builder
    

References

License

Red Hat, the Shadowman logo, Ansible, and Ansible Tower are trademarks or registered trademarks of Red Hat, Inc. or its subsidiaries in the United States and other countries.

All other parts of this project are made available under the terms of the MIT License.

ansible-role-qcow2builder's People

Contributors

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