Skip to content

Instantly share code, notes, and snippets.

@Panky-codes
Last active November 14, 2022 08:50
Show Gist options
  • Save Panky-codes/d5615e6146d83102a49fc8adee9908ec to your computer and use it in GitHub Desktop.
Save Panky-codes/d5615e6146d83102a49fc8adee9908ec to your computer and use it in GitHub Desktop.
Ansible role for VMCTL provisioning
---
- name: Clone vmctl
git:
repo: https://github.com/OpenMPDK/vmctl.git
dest: /home/panky/SW/tools/vmctl
- name: Create .local bin dir
ansible.builtin.file:
path: /home/panky/.local/bin
state: directory
- name: Create a symbolic link to vmctl
ansible.builtin.file:
src: /home/panky/SW/tools/vmctl/vmctl
dest: /home/panky/.local/bin/vmctl
state: link
- name: Create vms config dir
ansible.builtin.file:
path: /home/panky/vms/config
state: directory
- name: Create vms img dir
ansible.builtin.file:
path: /home/panky/vms/img
state: directory
- name: Copy config files
ansible.builtin.copy:
src: /home/panky/SW/tools/vmctl/examples/vm/
dest: /home/panky/vms/config/
remote_src: yes
- name: Download debian cloud img
ansible.builtin.get_url:
url: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
dest: /home/panky/vms/img/base.qcow2
force: yes
- name: Install packages for qemu and vmctl
become: yes
become_method: sudo
ansible.builtin.apt:
name:
- qemu-system-x86
- qemu-utils
- cloud-init
- cloud-image-utils
- ninja-build
- pkg-config
- libglib2.0-dev
- libpixman-1-dev
- libattr1-dev
- libcap-ng-dev
- libvirt-clients
- libvirt-daemon
- virtinst
- pip
update_cache: yes
- name: Increase the base size of the img
ansible.builtin.shell: qemu-img resize base.qcow2 8G
args:
chdir: /home/panky/vms/img/
- name: generate SSH key for vmctl
openssh_keypair:
path: /home/panky/.ssh/vmctl
type: rsa
size: 4096
state: present
force: no
- name: Install stormssh module
pip:
name: stormssh
- name: Add vmctl to ssh config
community.general.ssh_config:
host: vmctl
user: panky
remote_user: root
hostname: localhost
identity_file: "/home/panky/.ssh/vmctl"
port: '2222'
state: present
- name: Check if seed.img is present
stat:
path: /home/panky/vms/img/seed.img
register: seed_result
- name: create seed.img for cloud init
ansible.builtin.shell: |
./generate-cloud-config-seed.sh /home/panky/.ssh/vmctl.pub
mv seed.img /home/panky/vms/img
args:
chdir: /home/panky/SW/tools/vmctl/contrib
when: not seed_result.stat.exists
- name: Add panky to kvm
become: yes
become_method: sudo
ansible.builtin.user:
name: panky
groups: kvm
append: yes
# Install qemu
#
- name: Clone qemu
git:
repo: https://github.com/qemu/qemu.git
dest: /home/panky/SW/tools/qemu
version: v7.1.0
depth: 1
- name: configure qemu
ansible.builtin.shell: |
./configure --target-list=x86_64-softmmu,i386-softmmu --enable-virtfs --disable-werror
args:
chdir: /home/panky/SW/tools/qemu
- name: Build qemu with "{{ make_num_jobs }}" cores
ansible.builtin.shell: |
make -j"{{ make_num_jobs }}"
args:
chdir: /home/panky/SW/tools/qemu
- name: Install qemu
make:
chdir: /home/panky/SW/tools/qemu
target: install
become: yes
become_method: sudo
- name: Reset connection so that kvm group is accessible
meta: reset_connection
- name: init the vm with cloud init
ansible.builtin.shell: /home/panky/.local/bin/vmctl -c config/nvme.conf run -c
args:
chdir: /home/panky/vms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment