Code Monkey home page Code Monkey logo

ansible-kvm's Introduction

ansible-kvm

An Ansible role to install KVM

Requirements

Install required Ansible roles:

sudo ansible-galaxy install -r requirements.yml

Role Variables

defaults/main.yml

Dependencies

None

Example Playbook

- hosts: kvm_hosts
  vars: {}
  roles:
    - role: ansible-kvm
  tasks: []

Booting a VM from ISO

You can boot a defined VM up with an ISO by using the following example:

NOTE: Defined in your vars. Also, ensure that the default kvm_manage_vms: false is changed to kvm_manage_vms: true.

kvm_manage_vms: true
kvm_vms:
  - name: test_vm
    autostart: true
    # Define boot devices in order of preference
    boot_devices:
      - cdrom
      - network
      - hd
    cdrom:
      source: /path/to/iso
    graphics: false
    # Define disks in MB
    disks:
      - disk_driver: virtio
        name: test_vm.1
        size: 36864
    memory: 512
    network_interfaces:
      - source: default
        network_driver: virtio
        portgroup: vlan-102
        type: network
    state: running
    vcpu: 1

License

MIT

Author Information

Larry Smith Jr.

Buy Me A Coffee

ansible-kvm's People

Contributors

2stacks avatar demostenes777 avatar halleelyasaf avatar maurerr avatar mrlesmithjr avatar msaf1980 avatar roedie avatar teebor-choka avatar tomas321 avatar trly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-kvm's Issues

Centos7: list index out of range

Hi @mrlesmithjr , I just got this on a freshly-installed Centos7 (no virtual envs) Python 2.7.5
Should I install python3 ? Thanks, sorry to bother you on a Sunday.

Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

When I ran the ansible-galaxy install -r requirements.yml

ansible-galaxy 2.4.2.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/bpabon/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-galaxy
  python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
Opened /home/bpabon/.ansible_galaxy
found role {'scm': 'git', 'src': 'https://github.com/mrlesmithjr/ansible-config-interfaces.git', 'version': '', 'name': 'ansible-config-interfaces'} in yaml file
Processing role ansible-config-interfaces
- extracting ansible-config-interfaces to /etc/ansible/roles/ansible-config-interfaces
- extracting ansible-config-interfaces to /usr/share/ansible/roles/ansible-config-interfaces
ERROR! Unexpected Exception, this is probably a bug: list index out of range
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-galaxy", line 106, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/site-packages/ansible/cli/galaxy.py", line 150, in run
    self.execute()
  File "/usr/lib/python2.7/site-packages/ansible/cli/__init__.py", line 155, in execute
    fn()
  File "/usr/lib/python2.7/site-packages/ansible/cli/galaxy.py", line 393, in execute_install
    installed = role.install()
  File "/usr/lib/python2.7/site-packages/ansible/galaxy/role.py", line 332, in install
    self.path = self.paths[nextidx]
IndexError: list index out of range

boot from iso image

dear sir,

thank you for this effort. How would it be possible to boot a VM directly from an ISO for an unattended install with this role?

kind regards!

Fail on Linux Mint

Hi,

the role can't detect when running on Linux Mint.

$ ansible localhost -m setup | grep ansible_distribution
"ansible_distribution": "Linux Mint",
"ansible_distribution_file_variety": "Debian",
"ansible_distribution_major_version": "19",
"ansible_distribution_release": "tina",
"ansible_distribution_version": "19.2",

Consider introducing releases and API versioning

Hi and thanks for this amazing role.

I created a pull request #29 (molecule testing using Travis CI, code refactoring, external dependency removals...). All the changes were internal and they have not touched the external API yet.

However, in case of future (API breaking) changes, it would be prudent to introduce versioning to API (e.g. using releases).

Please, consider creating releases indicating possible API changes for future users and allowing them to fix to a specific major.minor.revision release instead of a commit ID.

Define the MAC address of an interface

Is your feature request related to a problem? Please describe.
I am using this role to create VMs for an OpenStack deployment using triple-o and being able to define the MAC address of the interface makes easier a step of the deployment called introspection, where the MAC address needs to be used.

Describe the solution you'd like
I will like to have the possibility to define the MAC addresses of the interfaces of the VM as follows:

      - source: provisioning
        network_driver: virtio
        type: network
        portgroup: vlan-40
        mac: CA:FE:CA:FE:CA:FE

Describe alternatives you've considered
I could use virsh to get the MAC addresseses, but these will be dinamically assigned and I would have to process them to generate the config files required by OpenStack every time I launch my automation.

Example from README

Hi @mrlesmithjr, thanks for the role, I tried this yesterday with the example you show on the README, for the KVM setup on the host this worked fine, though I do have a question about the PR #24

My kvm_host is a bare metal centos 1810 as is the kvm_guest I'm trying to provision.

The ansible output shows that at the point where it trys to provision the guest it skips the tasks.

TASK [mrlesmithjr.kvm : config_vms | Defining VM(s)] *******************************************************************************************************************************************************************************************************************
skipping: [nuc] => (item={'name': 'red', 'autostart': True, 'boot_devices': ['cdrom', 'network', 'hd'], 'cdrom': {'source': '/root/guest.iso'}, 'graphics': False, 'disks': [{'disk_driver': 'virtio', 'name': 'red', 'size': 36864}], 'memory': 4048, 'network_interfaces': [{'source': 'default', 'network_driver': 'virtio', 'type': 'network'}], 'state': 'running', 'vcpu': 2})

TASK [mrlesmithjr.kvm : config_vms | Defining VM(s)] *******************************************************************************************************************************************************************************************************************
skipping: [nuc] => (item={'name': 'red', 'autostart': True, 'boot_devices': ['cdrom', 'network', 'hd'], 'cdrom': {'source': '/root/guest.iso'}, 'graphics': False, 'disks': [{'disk_driver': 'virtio', 'name': 'red', 'size': 36864}], 'memory': 4048, 'network_interfaces': [{'source': 'default', 'network_driver': 'virtio', 'type': 'network'}], 'state': 'running', 'vcpu': 2})

...

See below for how I've constructed the playbook. Any suggestions much appreciated.

# install the required roles
#   $ ansible-galaxy install mrlesmithjr.kvm

# create an inventory file - 
#   $ cat inventory
#   [kvm_hosts]
#   nuc
# 
#   [all:vars]
#   ansible_user=root
#   ansible_ssh_pass=xxxx
#   guest_iso_url=http://ftp.heanet.ie/pub/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso

# run the playbook 
#   $ ansible-playbook -i inventory kvm.yml


- hosts: kvm_hosts
  become: true
  tasks:
    - name: Downloading guest iso, go get a cup of tea ...
      get_url:
        url: "{{guest_iso_url}}"
        dest: /root/guest.iso
        mode: 0440

- hosts: kvm_hosts
  become: true
  vars:
    kvm_vms:
    - name: red
      autostart: true
      # Define boot devices in order of preference
      boot_devices:
        - cdrom
        - network
        - hd
      cdrom:
        source: /root/guest.iso
      graphics: false
      # Define disks in MB
      disks:
        - disk_driver: virtio
          name: red
          size: 36864
      memory: 4048
      network_interfaces:
        - source: default
          network_driver: virtio
          type: network
      state: running
      vcpu: 2
  roles:
    - role: mrlesmithjr.kvm

# see https://github.com/mrlesmithjr/ansible-kvm/pull/24 - though I dont think this is needed as I see a log entry for the same check
- hosts: kvm_hosts
  become: true
  tasks:
    - name: config_kvm | starting libvirt service 
      service: 
        name: "{{ kvm_service_name }}"
        state: started
        enabled: yes

Add option lib-virt network with single tag

I need a way to create a lib-virt network that when used by a kvm guest would add the guests vnic as an access port in a specific vlan in openvswitch. Some lib-virt integrations such as MAAS do not support adding a vnic to a specific 'portgroup'.

Ex. network created with virsh net-define

<network>
  <name>maas</name>
  <uuid>3f1a2ff2-8d90-4883-906b-6a818d8baabf</uuid>
  <forward mode='bridge'/>
  <bridge name='ovsbr0'/>
  <vlan>
    <tag id='193'/>
  </vlan>
  <virtualport type='openvswitch'/>
</network>

Adding a kvm guest to this network results in the following openvswitch output

ovs-vsctl show
a0a40804-5b4e-4133-b0a6-1b186d95e147
    Bridge "ovsbr0"
        Port "vnet0"
            tag: 193
            Interface "vnet0"
        Port "ovsbr0"
            Interface "ovsbr0"
                type: internal
        Port "enp4s0"
            Interface "enp4s0"
    ovs_version: "2.5.4"

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.