Skip to content
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

Update default ubuntu image url #35

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ jobs:
matrix:
include:
- distro: 'jammy'
url: 'https://releases.ubuntu.com/jammy/ubuntu-22.04.3-live-server-amd64.iso'
net: '192.168.255.0/24'
- distro: 'focal'
url: 'https://releases.ubuntu.com/focal/ubuntu-20.04.6-live-server-amd64.iso'
net: '192.168.254.0/24'

steps:
Expand Down
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
fileignoreconfig:
- filename: poetry.lock
ignore_detectors: [filecontent]
- filename: pyproject.toml
ignore_detectors: [filecontent]
- filename: molecule/templates/vm.xml.j2
ignore_detectors: [filecontent]
- filename: molecule/default/molecule.yml
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
.PHONY: all ${MAKECMDGOALS}

MOLECULE_SCENARIO ?= default
MOLECULE_DOCKER_IMAGE ?= ubuntu2004
GALAXY_API_KEY ?=
GITHUB_REPOSITORY ?= $$(git config --get remote.origin.url | cut -d: -f 2 | cut -d. -f 1)
GITHUB_ORG = $$(echo ${GITHUB_REPOSITORY} | cut -d/ -f 1)
GITHUB_REPO = $$(echo ${GITHUB_REPOSITORY} | cut -d/ -f 2)
REQUIREMENTS = requirements.yml
UBUNTU_DISTRO = jammy
UBUNTU_SHASUMS = https://releases.ubuntu.com/${UBUNTU_DISTRO}/SHA256SUMS
UBUNTU_MIRROR = $$(dirname ${UBUNTU_SHASUMS})
UBUNTU_ISO = $$(curl -s ${UBUNTU_SHASUMS} | grep "live-server" | awk '{print $$2}' | sed -e 's/\*//g')

all: install version lint test

test: lint
MOLECULE_DISTRO=${UBUNTU_DISTRO} \
MOLECULE_ISO=${UBUNTU_MIRROR}/${UBUNTU_ISO} \
poetry run molecule $@ -s ${MOLECULE_SCENARIO}

install:
Expand All @@ -34,7 +39,9 @@ collections:
requirements: roles collections

dependency create prepare converge idempotence side-effect verify destroy login reset:
MOLECULE_DOCKER_IMAGE=${MOLECULE_DOCKER_IMAGE} poetry run molecule $@ -s ${MOLECULE_SCENARIO}
MOLECULE_DISTRO=${UBUNTU_DISTRO} \
MOLECULE_ISO=${UBUNTU_MIRROR}/${UBUNTU_ISO} \
poetry run molecule $@ -s ${MOLECULE_SCENARIO}

ignore:
poetry run ansible-lint --generate-ignore
Expand Down
51 changes: 0 additions & 51 deletions molecule/default/cleanup.yml

This file was deleted.

46 changes: 21 additions & 25 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,39 @@
---
- name: Spawn KVM guests

hosts: localhost

become: true

vars_files:
- vars.yml
pre_tasks:

- name: Install disk utils
ansible.builtin.apt:
name:
- parted
- lvm2

tasks:

- name: Cache installer iso
ansible.builtin.get_url:
url: "{{ iso_installer.url }}"
dest: "{{ iso_installer.dest | urlsplit('path') }}"
url: "{{ ubuntu_installer_url }}"
dest: "{{ ubuntu_installer_dest | urlsplit('path') }}"

- name: Build guest installer isos
ansible.builtin.include_role:
name: nephelaiio.ubuntu_installer
vars:
ubuntu_installer_interface_name: enp1s0
ubuntu_installer_target_dir: "{{ cache_dir }}"
ubuntu_installer_image_url: "{{ iso_installer.dest }}"
ubuntu_installer_target_dir: "{{ molecule_libvirt_path }}"
ubuntu_installer_image_url: "{{ ubuntu_installer_dest }}"
ubuntu_installer_hostname: "{{ guest.installer_hostname }}"
ubuntu_installer_username: molecule
ubuntu_installer_password: "{{ 'molecule' | password_hash('sha512') }}"
ubuntu_installer_sshkey:
- "{{ lookup('file', kvm_keypair + '.pub') }}"
- "{{ lookup('file', molecule_kvm_keypair + '.pub') }}"
ubuntu_installer_interface: "{{ guest.installer_interface }}"
ubuntu_installer_partman_method: "{{ guest.installer_partitioning_method }}"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"

- name: Destroy KVM guest
community.libvirt.virt:
Expand All @@ -46,7 +42,7 @@
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"
failed_when: false

- name: Undefine KVM guest
Expand All @@ -56,31 +52,31 @@
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"
failed_when: false

- name: Destroy KVM guest disks
ansible.builtin.file:
path: "{{ guest_disk }}"
state: absent
vars:
guest_disk: "{{ cache_dir }}/{{ guest.installer_hostname }}.img"
guest_disk: "{{ molecule_libvirt_path }}/{{ guest.installer_hostname }}.img"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"

- name: Create KVM guest disks
ansible.builtin.command: "qemu-img create {{ guest_disk }} {{ guest_disk_size }}"
args:
creates: "{{ guest_disk }}"
vars:
guest_disk: "{{ cache_dir }}/{{ guest.installer_hostname }}.img"
guest_disk: "{{ molecule_libvirt_path }}/{{ guest.installer_hostname }}.img"
guest_disk_size: "{{ guest.installer_disk_size }}"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"

- name: Manage permissions for KVM guest disks
ansible.builtin.file:
Expand All @@ -89,28 +85,28 @@
group: kvm
mode: 0666
vars:
guest_disk: "{{ cache_dir }}/{{ guest.installer_hostname }}.img"
guest_disk: "{{ molecule_libvirt_path }}/{{ guest.installer_hostname }}.img"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"

- name: Create KVM guest
community.libvirt.virt:
xml: "{{ xml_template }}"
command: define
vars:
guest_hostname: "{{ guest.installer_hostname }}"
guest_bridge: "{{ bridge_name }}"
guest_iso: "{{ cache_dir }}/{{ guest_hostname }}.iso"
guest_disk_path: "{{ cache_dir }}/{{ guest.installer_hostname }}.img"
guest_network: "{{ molecule_libvirt_network }}"
guest_iso: "{{ molecule_libvirt_path }}/{{ guest_hostname }}.iso"
guest_disk_path: "{{ molecule_libvirt_path }}/{{ guest.installer_hostname }}.img"
guest_mac: "{{ '52:54:00' | random_mac(seed=guest_hostname) }}"
guest_disk_format: raw
xml_template: "{{ lookup('template', 'vm.xml.j2') }}"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"

- name: Start KVM guest
community.libvirt.virt:
Expand All @@ -121,4 +117,4 @@
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ guests }}"
loop: "{{ molecule_kvm_guests }}"
65 changes: 65 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- name: Destroy KVM guests
hosts: localhost
become: true
tasks:
- name: Destroy KVM guest
community.libvirt.virt:
state: destroyed
name: "{{ guest.installer_hostname }}"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ molecule_kvm_guests }}"
failed_when: false

- name: Undefine KVM guest
community.libvirt.virt:
command: undefine
name: "{{ guest.installer_hostname }}"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ molecule_kvm_guests }}"
failed_when: false

- name: Destroy KVM guest disks
ansible.builtin.file:
path: "{{ guest_disk }}"
state: absent
vars:
guest_disk: "{{ molecule_libvirt_path }}/{{ guest.installer_hostname }}.img"
loop_control:
loop_var: guest
label: "{{ guest.installer_hostname }}"
loop: "{{ molecule_kvm_guests }}"


- name: Destroy libvirt network and storage
hosts: localhost
become: true
vars_files:
- vars.yml
tasks:
- name: Stop libvirt network
community.libvirt.virt_net:
command: destroy
name: "{{ _libvirt_network }}"
when: _libvirt_network != "default"
failed_when: false

- name: Delete libvirt network
community.libvirt.virt_net:
command: undefine
name: "{{ _libvirt_network }}"
when: _libvirt_network != "default"

- name: Undefine libvirt pool
community.libvirt.virt_pool:
state: undefined
name: "{{ _libvirt_pool }}"

- name: Destroy libvirt pool
ansible.builtin.file:
path: "{{ _libvirt_pool }}"
state: absent
Loading
Loading