Skip to content

Commit 117943c

Browse files
committed
updates to Ansible 2.17
* host is now Ubuntu >=20.04 * add Ansible Lint support and GHA * add Devcontainer for easy ansible lint check
1 parent 75984ce commit 117943c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+672
-548
lines changed

.config/ansible-lint.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
exclude_paths:
3+
- ".github"
4+
- "/docker-compose.yml"
5+
- "/docker-compose.*.yml"
6+
7+
kinds:
8+
- playbook: "tests/urlshort_simple.yml"
9+
10+
skip_list:
11+
- package-latest # we don't change this role with all the versions
12+
- latest[git] # same
13+
- role-name[path] # we nest roles here to avoid 1000 dependencies
14+
- var-naming[pattern] # we use uppercase variables for stored facts
15+
- var-naming[no-role-prefix] # our role variables don't follow this pattern

.devcontainer/devcontainer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "libvirt-ansible-dev",
3+
"dockerComposeFile": [
4+
"docker-compose.yml"
5+
],
6+
"service": "ansible",
7+
"overrideCommand": true,
8+
"containerUser": "root",
9+
"workspaceFolder": "/etc/ansible/roles/hicknhack-software.libvirt",
10+
// "capAdd": ["SYS_ADMIN", "SYS_RESOURCE"],
11+
// "securityOpt": ["seccomp=unconfined", "label=disable", "apparmor=unconfined"],
12+
"updateRemoteUserUID": true,
13+
"postStartCommand": ".devcontainer/install_requirements.sh",
14+
"customizations": {
15+
"vscode": {
16+
"extensions": [
17+
"redhat.ansible"
18+
],
19+
"settings": {
20+
"files.associations": {
21+
"**/defaults/*.yml": "ansible",
22+
"**/handlers/*.yml": "ansible",
23+
"**/tasks/*.yml": "ansible",
24+
"**/vars/*.yml": "ansible",
25+
"**/templates/*.j2": "ansible-jinja"
26+
}
27+
}
28+
}
29+
}
30+
}

.devcontainer/docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: hnh-libvirt
3+
4+
volumes:
5+
ansible-colletions:
6+
7+
services:
8+
ansible:
9+
image: "ghcr.io/ansible/community-ansible-dev-tools:latest"
10+
volumes:
11+
- ..:/etc/ansible/roles/hicknhack-software.libvirt
12+
- ansible-colletions:/root/.ansible/collections
13+
working_dir: /etc/ansible/roles/hicknhack-software.libvirt
14+
tty: true
15+
stdin_open: true
16+
environment:
17+
- ANSIBLE_HOST_KEY_CHECKING=false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
4+
pushd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null
5+
6+
ansible-galaxy install -r requirements.yml

.github/workflows/ansible_lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Ansible Lint
2+
3+
on: push
4+
5+
jobs:
6+
ansible-lint:
7+
name: "Run Ansible Lint"
8+
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Make Symlink
14+
run: >-
15+
mkdir -p /home/runner/.ansible/roles
16+
&& ln -s $(pwd) /home/runner/.ansible/roles/hicknhack-software.libvirt
17+
18+
- name: Run Ansible Lint
19+
uses: ansible/ansible-lint@main
20+
with:
21+
requirements_file: "requirements.yml"

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ansible.python.interpreterPath": "/bin/python3",
3+
"files.associations": {
4+
"**/defaults/*.yml": "ansible",
5+
"**/handlers/*.yml": "ansible",
6+
"**/tasks/*.yml": "ansible",
7+
"**/vars/*.yml": "ansible",
8+
"**/templates/*.j2": "ansible-jinja"
9+
}
10+
}

domain/create/defaults/main.yml

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
---
22
libvirt_domain:
33
# basic arguments
4+
type: "kvm"
45
groups: [] # names of Ansible nodes/groups used to provision the domain
5-
name: # name/uuid of the domain (empty means new uuid)
6-
title: '' # title of the vm
7-
description: '' # description of the vm
8-
apt_mirror: ''
6+
name: "{{ inventory_hostname }}" # name/uuid of the domain (empty means new uuid)
7+
title: "" # title of the vm
8+
description: "" # description of the vm
9+
apt_mirror: ""
910
# note: if you do not provide a domain_id each run will create a new vm!
1011

1112
# host access ports
@@ -21,27 +22,27 @@ libvirt_domain:
2122
vm:
2223
memory: "512MiB" # RAM memory available to the VM
2324
vcpu: 1 # number of cores designated to the VM
24-
vcpu_placement: 'static' # options 'auto', 'static', defaults to 'numatune'
25+
vcpu_placement: "static" # options 'auto', 'static', defaults to 'numatune'
2526
vcpu_cpuset: [] # list of host CPU numbers the VM can run on
26-
networks: ['default'] # libvirts id of networks this VM is part of
27+
networks: ["default"] # libvirts id of networks this VM is part of
2728
disk_size: "12G" # use this to change first disk size
28-
features: ['acpi', 'apic', 'pae'] # vm features available
29+
features: ["acpi", "apic", "pae"] # vm features available
2930

3031
# features
31-
serial_console: yes # make a console on serial port 0 available
32-
vnc: no
33-
autostart: yes # should the domain VM start after reboot of the host
32+
serial_console: true # make a console on serial port 0 available
33+
vnc: false
34+
autostart: true # should the domain VM start after reboot of the host
3435

3536
# Valid install_types:
36-
install_type: 'base-image' # way to install the VM (this only affects the first run!)
37+
install_type: "base-image" # way to install the VM (this only affects the first run!)
3738

3839
#
3940
# 1. 'base-image'
4041
# ----------
4142
# a simple image
4243
base_image:
4344
path: # path to the cloud image for the domain
44-
mode: 'snapshot' # options: snapshot, copy
45+
mode: "snapshot" # options: snapshot, copy
4546

4647
extra_disks: []
4748
# - id: 'data-disk' # logical name of the disk (required)
@@ -56,7 +57,7 @@ libvirt_domain:
5657
# lvm_group: '' # name of volume group (required)
5758

5859
# cloud initialisation method
59-
init_mode: 'cloud-config' # options: cloud-config, configdrive (empty will skip any initialisation)
60+
init_mode: "cloud-config" # options: cloud-config, configdrive (empty will skip any initialisation)
6061

6162
#
6263
# Cloud-Config
@@ -67,14 +68,16 @@ libvirt_domain:
6768
# see https://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/doc/examples/cloud-config-user-groups.txt
6869
cloud_config:
6970
users:
70-
- name: 'ubuntu'
71-
gecos: 'Ubuntu'
72-
ssh-authorized-keys: [] # required!
73-
shell: '/bin/bash'
74-
sudo: 'ALL=(ALL) NOPASSWD:ALL'
75-
groups: 'adm,audio,cdrom,dialout,floppy,video,plugdev,dip,netdev' # comma separated string!
71+
- name: "ubuntu"
72+
gecos: "Ubuntu"
73+
ssh_authorized_keys: [] # required!
74+
shell: "/bin/bash"
75+
sudo: "ALL=(ALL) NOPASSWD:ALL"
76+
groups: "adm,audio,cdrom,dialout,floppy,video,plugdev,dip,netdev" # comma separated string!
7677
bootcmd: []
77-
timezone: '' # like Europe/Berlin
78+
timezone: "" # like Europe/Berlin
79+
packages:
80+
- python
7881

7982
#
8083
# ConfigDrive
@@ -85,7 +88,8 @@ libvirt_domain:
8588
#
8689
# all the options intended to show up in the configdrive meta_data.json
8790
configdrive:
88-
meta_data: ''
91+
meta_data:
92+
""
8993
# hostname: '{{ libvirt_result_domain_name }}'
9094
# username: 'Admin'
9195
# groups: 'Administrators' # comma separated string!
@@ -94,15 +98,15 @@ libvirt_domain:
9498
# authorized_keys: ...
9599

96100
# content of the user data (skipped if empty)
97-
user_data: ''
101+
user_data: ""
98102
# executed for content of first line
99103
# #ps1 => Powershell
100104
# rem cmd => Cmd/Batch
101105
# #! => Bash (if installed)
102106

103-
# extra file structure inside the configdrive
104-
#extra_files:
105-
# filename: text content
107+
## extra file structure inside the configdrive
108+
# extra_files:
109+
# filename: text content
106110

107111
# libvirt os settings - see: https://libvirt.org/formatdomain.html#elementsOS
108112
os: "{{ libvirt_os_virtualized_x86_64 }}"
@@ -127,8 +131,9 @@ libvirt_domain:
127131
# - 'smx' # feature with default policy 'require'
128132

129133
# basic arguments
134+
libvirt_domain_type: "{{ libvirt_domain.type | default('kvm', true) }}"
130135
libvirt_domain_groups: "{{ libvirt_domain.groups | default([], true) }}" # names of Ansible nodes/groups used to provision the domain
131-
libvirt_domain_name: "{{ libvirt_domain.name | default('', true) }}" # name/uuid of the domain (empty means new uuid)
136+
libvirt_domain_name: "{{ libvirt_domain.name | default(inventory_hostname, true) }}" # name/uuid of the domain (empty means new uuid)
132137
libvirt_domain_title: "{{ libvirt_domain.title | default('', true) }}" # title of the vm
133138
libvirt_domain_description: "{{ libvirt_domain.description | default('', true) }}" # description of the vm
134139
# note: if you do not provide a domain_id each run will create a new vm!
@@ -144,7 +149,8 @@ libvirt_winrm_port: "{{ (libvirt_domain.host_ports | default({}, true)).winrm |
144149
# default VM configuration
145150
libvirt_vm_memory: "{{ (libvirt_domain.vm | default({}, true)).memory | default('512MiB', true) }}" # RAM memory available to the VM
146151
libvirt_vm_vcpu: "{{ (libvirt_domain.vm | default({}, true)).vcpu | default('1', true) }}" # number of cores designated to the VM
147-
libvirt_vm_vcpu_placement: "{{ (libvirt_domain.vm | default({}, true)).vcpu_placement | default('static', true) }}" # options 'auto', 'static', defaults to 'numatune'
152+
# options 'auto', 'static', defaults to 'numatune'
153+
libvirt_vm_vcpu_placement: "{{ (libvirt_domain.vm | default({}, true)).vcpu_placement | default('static', true) }}"
148154
libvirt_vm_vcpu_cpuset: "{{ (libvirt_domain.vm | default({}, true)).vcpu_cpuset | default([], true) }}" # list of host CPU numbers the VM can run on
149155
libvirt_vm_networks: "{{ (libvirt_domain.vm | default({}, true)).networks | default(['default'], true) }}" # libvirts id of networks this VM is part of
150156
libvirt_vm_disk_size: "{{ (libvirt_domain.vm | default({}, true)).disk_size | default('12G', true) }}" # use this to change first disk size
@@ -180,7 +186,7 @@ libvirt_extra_disks: "{{ libvirt_domain.extra_disks | default([], true) }}"
180186
# cloud initialisation method
181187
libvirt_init_mode: "{{ libvirt_domain.init_mode | default('cloud-config', true) }}" # options: cloud-config, configdrive (empty will skip any initialisation)
182188

183-
libvirt_apt_mirror: "{{ libvirt_domain.apt_mirror | default('', true) }}"
189+
libvirt_apt_mirror: "{{ libvirt_domain.apt_mirror | default('', true) }}"
184190

185191
#
186192
# Cloud-Config
@@ -192,20 +198,30 @@ libvirt_apt_mirror: "{{ libvirt_domain.apt_mirror | default('', true) }}"
192198
libvirt_cloud_config_users: "{{ (libvirt_domain.cloud_config | default({}, true)).users | default([libvirt_cloud_config_default_user], true) }}"
193199

194200
libvirt_cloud_config_default_user:
195-
name: 'ubuntu'
196-
gecos: 'Ubuntu'
197-
ssh-authorized-keys: [] # required!
198-
shell: '/bin/bash'
199-
sudo: 'ALL=(ALL) NOPASSWD:ALL'
200-
groups: 'adm,audio,cdrom,dialout,floppy,video,plugdev,dip,netdev' # comma separated string!
201+
name: "ubuntu"
202+
gecos: "Ubuntu"
203+
ssh_authorized_keys: [] # required!
204+
shell: "/bin/bash"
205+
sudo: "ALL=(ALL) NOPASSWD:ALL"
206+
groups: "adm,audio,cdrom,dialout,floppy,video,plugdev,dip,netdev" # comma separated string!
201207

202208
libvirt_cloud_config_bootcmd: "{{ (libvirt_domain.cloud_config | default({}, true)).bootcmd | default([], true) }}"
203209

204210
# example bootcmd that enables dhcp for ipv6 on ubuntu 16.04 guests
205-
libvirt_cloud_config_ipv6_dhcp_bootcmd: [ cloud-init-per, once, ipv6-dhcp, "/bin/sh", "-c", "echo iface ens2 inet6 dhcp >> /etc/network/interfaces.d/51-cloud-init-ipv6.cfg" ]
211+
libvirt_cloud_config_ipv6_dhcp_bootcmd:
212+
[
213+
cloud-init-per,
214+
once,
215+
ipv6-dhcp,
216+
"/bin/sh",
217+
"-c",
218+
"echo iface ens2 inet6 dhcp >> /etc/network/interfaces.d/51-cloud-init-ipv6.cfg",
219+
]
206220

207221
libvirt_cloud_config_timezone: "{{ (libvirt_domain.cloud_config | default({}, true)).timezone | default('', true) }}"
208222

223+
libvirt_cloud_config_packages: "{{ (libvirt_domain.cloud_config | default({}, true)).packages | default([], true) | list }}"
224+
209225
#
210226
# ConfigDrive
211227
# ===========
@@ -217,7 +233,7 @@ libvirt_cloud_config_timezone: "{{ (libvirt_domain.cloud_config | default({}, tr
217233
libvirt_configdrive_meta_data: "{{ (libvirt_domain.configdrive | default({}, true)).meta_data | default(libvirt_configdrive_default_meta_data, true) }}"
218234

219235
libvirt_configdrive_default_meta_data:
220-
hostname: '{{ libvirt_result_domain_name }}'
236+
hostname: "{{ libvirt_result_domain_name }}"
221237
# username: 'Admin'
222238
# groups: 'Administrators' # comma separated string!
223239
# inject_user_password: True
@@ -235,17 +251,17 @@ libvirt_configdrive_user_data: "{{ (libvirt_domain.configdrive | default({}, tru
235251
libvirt_configdrive_files: "{{ (libvirt_domain.configdrive | default({}, true)).extra_files | default({}, true) | combine(libvirt_configdrive_base_files) }}"
236252

237253
libvirt_configdrive_base_files:
238-
'openstack/latest/meta_data.json': '{{ libvirt_configdrive_meta_data | to_json }}'
239-
'openstack/latest/user_data': '{{ libvirt_configdrive_user_data }}'
254+
"openstack/latest/meta_data.json": "{{ libvirt_configdrive_meta_data | to_json }}"
255+
"openstack/latest/user_data": "{{ libvirt_configdrive_user_data }}"
240256

241257
# libvirt os settings - see: https://libvirt.org/formatdomain.html#elementsOS
242258
libvirt_os_virtualized_x86_64:
243-
type: 'hvm'
244-
type_arch: 'x86_64'
259+
type: "hvm"
260+
type_arch: "x86_64"
245261

246262
libvirt_os_virtualized_x86:
247-
type: 'hvm'
248-
type_arch: 'i686'
263+
type: "hvm"
264+
type_arch: "i686"
249265

250266
libvirt_os: "{{ libvirt_domain.os | default(libvirt_os_virtualized_x86_64, true) }}"
251267
# type: 'hvm' # options 'hvm'*, 'linux', 'exe'
@@ -257,12 +273,12 @@ libvirt_os: "{{ libvirt_domain.os | default(libvirt_os_virtualized_x86_64, true)
257273
#
258274
# use these settings for easily migratable vms (default)
259275
libvirt_vm_cpu_migratable:
260-
match: 'exact' # options 'minimum', 'exact', 'strict'
261-
mode: 'custom' # options 'custom', 'host-model', 'host-passthrough'
276+
match: "exact" # options 'minimum', 'exact', 'strict'
277+
mode: "custom" # options 'custom', 'host-model', 'host-passthrough'
262278
#
263279
# use these settings for fast, supports nested virtualisation
264280
libvirt_vm_cpu_fast:
265-
mode: 'host-model' # everything libvirt understands
281+
mode: "host-model" # everything libvirt understands
266282

267283
libvirt_vm_cpu: "{{ libvirt_domain.cpu | default(libvirt_vm_cpu_fast, true) }}"
268284
# more options:
@@ -281,11 +297,11 @@ libvirt_vm_cpu: "{{ libvirt_domain.cpu | default(libvirt_vm_cpu_fast, true) }}"
281297
# ssh port foward configuration
282298
libvirt_ssh_base_port: 22000 # first host port for forwards to VM ssh
283299
libvirt_ssh_guest_port: 22 # guest port for ssh
284-
libvirt_host_ssh_ip_address: "{{ ansible_default_ipv4.address }}" # host ip address where ssh_ports are made available
300+
libvirt_host_ssh_ip_address: "{{ libvirt_host_vars.ansible_default_ipv4.address }}" # host ip address where ssh_ports are made available
285301
libvirt_host_ssh_destination_any: "0.0.0.0/0" # bind to any host ip subnet
286302
libvirt_host_ssh_destination_ip: "{{ libvirt_host_ssh_ip_address }}" # bind to any host ip subnet
287303
libvirt_host_ssh_destination: "{{ libvirt_host_ssh_destination_any }}" # ip subnet that is bound by port forwarding
288-
libvirt_host_accept_all_ports: no # if enabled the firewall is configured to allow all ports of the vm being accessed
304+
libvirt_host_accept_all_ports: false # if enabled the firewall is configured to allow all ports of the vm being accessed
289305

290306
libvirt_rdp_base_port: 33890 # first host port for forwards to VM rdp
291307
libvirt_rdp_guest_port: 3389 # guest port for rdp
@@ -296,13 +312,4 @@ libvirt_winrm_guest_port: 5986 # guest port for winrm (no ssl)
296312
# configuration options
297313
libvirt_images_path: "/var/lib/libvirt/images" # path on the host, where all the images are stored
298314

299-
# template for the stored facts hash (values are variable/fact names)
300-
libvirt_domain_fact_template: >-
301-
{
302-
u"ssh_port": {{ libvirt_result_ssh_port }},
303-
u"rdp_port": {{ libvirt_result_rdp_port }},
304-
u"winrm_port": {{ libvirt_result_winrm_port }},
305-
u"groups": {{ libvirt_domain_groups }}
306-
}
307-
308-
ansible_facts_path: '/etc/ansible/facts.d' # path where local Ansible facts are stored & read
315+
ansible_facts_path: "/etc/ansible/facts.d" # path where local Ansible facts are stored & read

0 commit comments

Comments
 (0)