Skip to content

Commit

Permalink
feat(libvirt): install libvirt, enable and start service, configure s…
Browse files Browse the repository at this point in the history
…torage pool.

add ansible galaxy and gh actions specifics
  • Loading branch information
smirta committed Jun 6, 2024
1 parent 589536d commit 6e5cd32
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 141 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: "chore(ci): "
12 changes: 12 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Release

on:
release:
types:
- published

jobs:
call-workflow:
uses: radiorabe/actions/.github/workflows/[email protected]
secrets:
GALAXY_API_KEY: ${{ secrets.GALAXY_API_KEY }}
12 changes: 12 additions & 0 deletions .github/workflows/semantic-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Semantic Release

on:
push:
branches:
- main

jobs:
call-workflow:
uses: radiorabe/actions/.github/workflows/[email protected]
secrets:
RABE_ITREAKTION_GITHUB_TOKEN: ${{ secrets.RABE_ITREAKTION_GITHUB_TOKEN }}
10 changes: 10 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Lint and Test

on:
pull_request:
branches:
- main

jobs:
call-workflow:
uses: radiorabe/actions/.github/workflows/[email protected]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# ansible-collection-foreman-libvirt

Ansible collection for making a host ready to serve as libvirt compute resource in Foreman.

## Roles

* [`libvirt`](https://github.com/radiorabe/ansible-collection-foreman-libvirt/tree/main/roles/libvirt)

## License

This collection is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
20 changes: 20 additions & 0 deletions galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace: radiorabe
name: foreman_libvirt
version: 0.0.0
readme: README.md
authors:
- Simon Nussbaum <@smirta>
description: Ansible collection for making a host ready to serve as libvirt compute resource in Foreman.
license_file: LICENSE
tags:
- radiorabe
- kvm
- libvirt
- qemu
- foreman
- cloudinit
dependencies: {}
repository: https://github.com/radiorabe/ansible-collection-foreman-libvirt
documentation: https://github.com/radiorabe/ansible-collection-foreman-libvirt/blob/main/README.md
homepage: hhttps://github.com/radiorabe/ansible-collection-foreman-libvirt
issues: https://github.com/radiorabe/ansible-collection-foreman-libvirt/issues
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requires_ansible: ">=2.11,<2.17"
38 changes: 0 additions & 38 deletions roles/cloudinit_image/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions roles/cloudinit_image/defaults/main.yml

This file was deleted.

20 changes: 0 additions & 20 deletions roles/cloudinit_image/meta/main.yml

This file was deleted.

35 changes: 0 additions & 35 deletions roles/cloudinit_image/tasks/main.yml

This file was deleted.

2 changes: 0 additions & 2 deletions roles/cloudinit_image/tests/inventory

This file was deleted.

5 changes: 0 additions & 5 deletions roles/cloudinit_image/tests/test.yml

This file was deleted.

46 changes: 21 additions & 25 deletions roles/libvirt/README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
Role Name
=========
# Ansible Role - radiorabe.foreman-libvirt.libvirt

A brief description of the role goes here.
Install libvirtd, enable and start libvirtd and create default storage pool using [`ansible.builtin.package`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/package_module.html), [`ansible.builtin.systemd_service`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/systemd_service_module.html) and [`ansible.builtin.template`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/template_module.html).

Requirements
------------
## Requirements

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Destination host needs to be able to download and install libvirt package from repository.

Role Variables
--------------
## Role Variables

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
| Variable | Default | Description |
| -------- | ------- | ----------- |
| `libvirt_storage_pool_path` | `/var/lib/libvirt/images/` | libvirt directory storage pool path. |
| `libvirt_storage_pool_name` | `default` | libvirt directory storage pool name. |
| `libvirt_libvirt_package_name` | `libvirt` | libvirt package name from repository. |
| `libvirt_libvirt_service_name` | `libvirtd` | libvirt service name. |

Dependencies
------------
## Dependencies

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
None

Example Playbook
----------------
## Example Playbook

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }
```yaml
- hosts: all
roles:
- libvirt
```
License
-------
## License
BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
This role is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License.
8 changes: 5 additions & 3 deletions roles/libvirt/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
# defaults file for kvm_provision
storage_pool_path: '/var/lib/libvirt/images/'
storage_pool_name: 'default'
# defaults file for libvirt
libvirt_storage_pool_path: /var/lib/libvirt/images/
libvirt_storage_pool_name: default
libvirt_libvirt_package_name: libvirt
libvirt_libvirt_service_name: libvirtd
13 changes: 9 additions & 4 deletions roles/libvirt/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
- name: Ensure requirements are in place
package:
name:
- libvirt
- "{{ libvirt_libvirt_package_name }}"
state: present
become: true

- name: Make sure libvirtd is enabled and started
ansible.builtin.systemd_service:
state: started
enabled: true
name: libvirtd
name: "{{ libvirt_libvirt_service_name }}"

- name: Write storage pool definition for {{ storage_pool_name }}
- name: Write storage pool definition for {{ libvirt_storage_pool_name }}
ansible.builtin.template:
src: templates/storage-pool.xml.j2
dest: /tmp/storage-pool.xml

- name: Create storage pool {{ storage_pool_name }}
- name: Create storage pool {{ libvirt_storage_pool_name }}
command: virsh pool-create /tmp/storage-pool.xml

- name: Remove storage pool definition /tmp/storage-pool.xml
file:
path: /tmp/storage-pool.xml
state: absent

0 comments on commit 6e5cd32

Please sign in to comment.