Skip to content

Commit abf82c2

Browse files
authored
Merge pull request #76 from lae/feature/vagrant
Add multi-machine Vagrantfile/playbook [ci skip]
2 parents b483e51 + 25160ed commit abf82c2

File tree

6 files changed

+90
-5
lines changed

6 files changed

+90
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
*.retry
77
/.project
88
/.pydevproject
9+
10+
fetch/
11+
.vagrant/

Vagrantfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "debian/buster64"
3+
4+
config.vm.provider :libvirt do |libvirt|
5+
libvirt.memory = 2048
6+
libvirt.cpus = 2
7+
end
8+
9+
N = 3
10+
(1..N).each do |machine_id|
11+
config.vm.define "pve-#{machine_id}" do |machine|
12+
machine.vm.hostname = "pve-#{machine_id}"
13+
14+
if machine_id == N
15+
machine.vm.provision :ansible do |ansible|
16+
ansible.limit = "all"
17+
ansible.playbook = "tests/vagrant/provision.yml"
18+
ansible.verbose = true
19+
end
20+
end
21+
end
22+
end
23+
end

library/collect_kernel_info.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55

66
from ansible.module_utils.basic import AnsibleModule
7+
from ansible.module_utils._text import to_text
78

89
def main():
910
module = AnsibleModule(
@@ -51,17 +52,17 @@ def main():
5152

5253
# This will likely output a path that considers the boot partition as /
5354
# e.g. /vmlinuz-4.4.44-1-pve
54-
booted_kernel = subprocess.check_output(["grep", "-o", "-P", "(?<=BOOT_IMAGE=).*?(?= )", "/proc/cmdline"]).strip()
55+
booted_kernel = to_text(subprocess.check_output(["grep", "-o", "-P", "(?<=BOOT_IMAGE=).*?(?= )", "/proc/cmdline"]).strip())
5556

5657
booted_kernel_package = ""
5758
old_kernel_packages = []
5859

5960
if params['lookup_packages']:
6061
for kernel in kernels:
6162
if kernel.split("/")[-1] == booted_kernel.split("/")[-1]:
62-
booted_kernel_package = subprocess.check_output(["dpkg-query", "-S", kernel]).split(":")[0]
63+
booted_kernel_package = to_text(subprocess.check_output(["dpkg-query", "-S", kernel])).split(":")[0]
6364
elif kernel != latest_kernel:
64-
old_kernel_packages.append(subprocess.check_output(["dpkg-query", "-S", kernel]).split(":")[0])
65+
old_kernel_packages.append(to_text(subprocess.check_output(["dpkg-query", "-S", kernel])).split(":")[0])
6566

6667
# returns True if we're not booted into the latest kernel
6768
new_kernel_exists = booted_kernel.split("/")[-1] != latest_kernel.split("/")[-1]

module_utils/pvesh.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import json
55
import re
66

7+
from ansible.module_utils._text import to_text
8+
79
class ProxmoxShellError(Exception):
810
"""Exception raised when an unexpected response code is thrown from pvesh."""
911
def __init__(self, response):
@@ -23,12 +25,13 @@ def run_command(handler, resource, **params):
2325
handler,
2426
resource,
2527
"--output=json"]
26-
for parameter, value in params.iteritems():
28+
for parameter, value in params.items():
2729
command += ["-{}".format(parameter), "{}".format(value)]
2830

2931
pipe = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
3032
(result, stderr) = pipe.communicate()
31-
stderr = stderr.splitlines()
33+
result = to_text(result)
34+
stderr = to_text(stderr).splitlines()
3235

3336
if len(stderr) == 0:
3437
if not result:

tests/vagrant/group_vars/all

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
ansible_python_interpreter: /usr/bin/python3
3+
4+
pve_group: all
5+
pve_extra_packages:
6+
- sl
7+
pve_check_for_kernel_update: true
8+
pve_reboot_on_kernel_update: true
9+
pve_run_system_upgrades: true
10+
pve_zfs_enabled: yes
11+
pve_zfs_zed_email: root@localhost
12+
pve_cluster_enabled: yes
13+
pve_datacenter_cfg:
14+
console: xtermjs
15+
pve_groups:
16+
- name: Admins
17+
comment: Administrators of this PVE cluster
18+
pve_users:
19+
- name: root@pam
20+
21+
pve_acls:
22+
- path: /
23+
roles: [ "Administrator" ]
24+
groups: [ "Admins" ]
25+
ntp_manage_config: true
26+
ntp_servers:
27+
- clock.sjc.he.net
28+
- clock.fmt.he.net
29+
- clock.nyc.he.net

tests/vagrant/provision.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
- hosts: all
2+
vars:
3+
role_name: lae.proxmox
4+
tasks:
5+
- block:
6+
- shell: pwd
7+
- name: Package up current working role
8+
shell: "cd $(git rev-parse --show-toplevel); git ls-files -z | xargs -0 tar -czvf $OLDPWD/{{ role_name }}.tar.gz"
9+
- name: Install packaged role
10+
shell: "ansible-galaxy install {{ role_name }}.tar.gz,devel-$(git rev-parse HEAD),{{ role_name }} --force"
11+
- name: Remove packaged role artifact
12+
file:
13+
dest: "{{ role_name }}.tar.gz"
14+
state: absent
15+
delegate_to: localhost
16+
run_once: True
17+
18+
- hosts: all
19+
become: True
20+
pre_tasks:
21+
- name: Install gnupg2
22+
apt:
23+
name: gnupg2
24+
roles:
25+
- geerlingguy.ntp
26+
- lae.proxmox

0 commit comments

Comments
 (0)