Skip to content

Optional VG creation #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
51 changes: 51 additions & 0 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# This is a basic workflow to help you get started with Actions
name: Molecule

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
pull_request:
branches:
- master
- tags/*

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
lint:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: install lint prerequisite
run: |
sudo apt-get update
sudo apt -y install python3-setuptools ansible-lint vagrant

- name: Install molecule
run: |
sudo apt update
sudo apt -y install python3-setuptools python3 python3-pip
sudo pip3 install wheel
sudo pip3 install molecule testinfra yamllint ansible-lint flake8 molecule-vagrant

- name: molecule lint
run: |
molecule lint

requirements:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: install prereq
run: |
ansible-galaxy role install -r requirements.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/__pychache__
56 changes: 24 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
---
language: python
python: "2.7"

# Use the new container infrastructure
sudo: false

# Install ansible
addons:
apt:
packages:
- python-pip

install:
# Install ansible
- pip install ansible ansible-lint

# Check ansible version
- ansible --version

# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
dist: bionic

# Compensate for repo name being different to the role
- ln -s $(pwd) ../stackhpc.libvirt-host

script:
# Run Ansible lint against the role
- ansible-lint tasks/main.yml

# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
language: python
python:
- "3.8"

before_install:
- |
sudo apt -y install bridge-utils dnsmasq-base ebtables libvirt-bin libvirt-dev qemu-kvm qemu-utils ruby-dev

- |
wget https://releases.hashicorp.com/vagrant/2.2.7/vagrant_2.2.7_x86_64.deb
sudo apt -y install ./vagrant_2.2.7_x86_64.deb
sudo vagrant plugin install vagrant-libvirt

- |
sudo apt-get -y purge python3-openssl && sudo apt-get -y autoremove
sudo apt-get update && sudo apt-get install -y ca-certificates curl gcc iproute2 python3 python3-dev sudo
curl -skL https://bootstrap.pypa.io/get-pip.py | sudo -H python3
sudo pip3 install wheel
sudo pip3 install netaddr python-vagrant yamllint testinfra flake8
sudo pip3 install ansible ansible-lint
sudo pip3 install -I molecule molecule-vagrant

script: travis_wait 60 sudo molecule test --scenario-name kvm
33 changes: 33 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ should be a dict containing the following items:
- `source` The name of the volume group. (only when type is `logical`)
- `pvs` A list of physical volumes the volume group consists of. (only when
type is `logical`)
- `pvs` A list of physical volumes the volume group consists of. (only when
type is `logical`). N.B. if specified, the volume group will be created on
top of the PVs, otherwise the logical volume should have been created before.

`libvirt_host_networks` is a list of networks to define and start. Each item
should be a dict containing the following items:
Expand Down Expand Up @@ -84,7 +87,7 @@ installed.
Dependencies
------------

None
* [The LVM role](https://github.com/mrlesmithjr/ansible-manage-lvm) You can install it using `ansible-galaxy install -r requirements.yml --roles-p ../community`

Example Playbook
----------------
Expand All @@ -94,6 +97,11 @@ Example Playbook
hosts: all
roles:
- role: stackhpc.libvirt-host
lvm_groups: # see according properties on [The LVM role](https://github.com/mrlesmithjr/ansible-manage-lvm)
- vgname: libvirtvg
disks:
- /dev/sdb1
create: true
libvirt_host_pools:
- name: my-pool
type: dir
Expand All @@ -104,10 +112,7 @@ Example Playbook
group: my-group
- name: lvm_pool
type: logical
source: vg1
target: /dev/vg1
pvs:
- /dev/sda3
source: libvirtvg
libvirt_host_networks:
- name: br-example
mode: bridge
Expand Down
21 changes: 20 additions & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,23 @@
service:
name: libvirtd
state: restarted
become: true
become: True
listen: restart libvirt

- name: Ensure libvirt storage pools are active
virt_pool:
name: "{{ item.name }}"
state: active
uri: "{{ libvirt_host_uri | default(omit, true) }}"
with_items: "{{ libvirt_host_pools }}"
become: True
listen: Ensure libvirt storage pools are active

- name: Ensure libvirt networks are active
virt_net:
name: "{{ item.name }}"
state: active
uri: "{{ libvirt_host_uri | default(omit, true) }}"
with_items: "{{ libvirt_host_networks }}"
become: True
listen: Ensure libvirt networks are active
18 changes: 18 additions & 0 deletions molecule/default/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Vagrant.configure(2) do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.memory = "512"
libvirt.cpus = 1
libvirt.driver = "kvm"
libvirt.graphics_type = 'none'
end

config.vm.box = "fedora/31-cloud-base"
config.vm.synced_folder ".", "/vagrant", disabled: true

config.vm.define "myvm" do |myvm|
# myvm.vm.network :public_network,
# :dev => "virbr0",
# :mode => "bridge",
# :type => "bridge"
end
end
64 changes: 64 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
- name: Converge
hosts: all
vars:
manage_lvm: true
lvm_groups:
- vgname: libvirt_vg
disks:
- /dev/sdb1
create: true
users_group_list:
- name: libvirt
systemusers_user_list:
- name: libvirt
group: libvirt
groups: wheel
libvirt_host_pools:
- name: libvirtpool
type: lvm2
source: libvirt_vg
libvirt_host_networks:
- name: ansible-virtualization-bridge
mode: bridge
bridge: bridge0
tasks:
- name: "Include ansible-role-libvirt-host"
include_role:
name: "ansible-role-libvirt-host"

- name: "Post converge - Install vagrant"
package:
name:
- qemu
- libvirt
- ruby-devel
- gcc
- qemu-kvm
- libxml2-devel
- libxslt-devel
- libguestfs-tools-c
- vagrant
- daemonize
state: present
become: true

- name: Copy vagrant file
copy:
src: Vagrantfile
dest: /home/vagrant/Vagrantfile
owner: vagrant
group: vagrant
mode: '0644'

- name: Execute Vagrant as daemon
command:
cmd: "daemonize -e /home/vagrant/myvmerr.log -o /home/vagrant/myvm.log -c /home/vagrant /usr/bin/vagrant up --provider=libvirt"
chdir: /home/vagrant
creates: /home/vagrant/myvm.log

- name: Wait until the string "auth" is in the vagrant log
wait_for:
path: /home/vagrant/myvm.log
search_regex: auth
timeout: 1000
39 changes: 39 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
dependency:
name: galaxy
options:
role-file: requirements.yml
roles-path: ../community
driver:
name: vagrant
provider:
name: virtualbox

lint: yamllint . && flake8 && ansible-lint --exclude=meta
platforms:
- name: Fedora-Molecule-Virtualization
box: fedora/31-cloud-base
memory: 8000
cpus: 4
provider_raw_config_args:
- "customize ['modifyvm', :id, '--nested-hw-virt', 'on']"
provider_override_args:
- "persistent_storage.enabled = true"
- "persistent_storage.location = 'molecule-virtualization.vdi'"
- "persistent_storage.size = 100"
- "persistent_storage.mount = false"
- "persistent_storage.diskdevice = '/dev/sdb'"
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: yes
pre_build_image: yes
provisioner:
name: ansible
env:
ANSIBLE_ROLES_PATH: ../../..:../../../community
verifier:
name: testinfra
env:
PYTHONWARNINGS: "ignore:.*U.*mode is deprecated:DeprecationWarning"
options:
v: 1
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions molecule/default/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""PyTest Fixtures."""
from __future__ import absolute_import
import os
import pytest


def pytest_runtest_setup(item):
"""Run tests only when under molecule with testinfra installed."""
try:
import testinfra
except ImportError:
pytest.skip("Test requires testinfra", allow_module_level=True)
if "MOLECULE_INVENTORY_FILE" in os.environ:
pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ["MOLECULE_INVENTORY_FILE"]
).get_hosts("all")
else:
pytest.skip(
"Test should run only from inside molecule.",
allow_module_level=True
)
Loading