1
1
{
2
2
pkgs ,
3
3
lib ,
4
+ docker-image-ubuntu ,
4
5
} :
5
6
let
6
- ubuntu-cloudimg =
7
- let
8
- cloudImg = builtins . fetchurl {
9
- url = "http://cloud-images-archive.ubuntu.com/releases/noble/release-20250430/ubuntu-24.04-server-cloudimg-amd64-root.tar.xz" ;
10
- sha256 = "sha256:0rfi3qqs0sqarixfic7pzjpx7d4vldv2d98c5zjv7b90mirznvf9" ;
11
- } ;
12
- in
13
- pkgs . runCommand "ubuntu-cloudimg" { nativeBuildInputs = [ pkgs . xz ] ; } ''
14
- mkdir -p $out
15
- tar --exclude='dev/*' \
16
- --exclude='etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service' \
17
- --exclude='etc/systemd/system/multi-user.target.wants/systemd-resolved.service' \
18
- --exclude='usr/lib/systemd/system/tpm-udev.service' \
19
- --exclude='usr/lib/systemd/system/systemd-remount-fs.service' \
20
- --exclude='usr/lib/systemd/system/systemd-resolved.service' \
21
- --exclude='var/lib/apt/lists/*' \
22
- -xJf ${ cloudImg } -C $out
23
- rm $out/bin $out/lib $out/lib64 $out/sbin
24
- mkdir -p $out/run/systemd && echo 'docker' > $out/run/systemd/container
25
- mkdir $out/var/lib/apt/lists/partial
26
- '' ;
27
-
28
- dockerImageUbuntu = pkgs . dockerTools . buildImage {
29
- name = "ubuntu-cloudimg" ;
30
- tag = "0.1" ;
31
- created = "now" ;
32
- extraCommands = ''
33
- ln -s usr/bin
34
- ln -s usr/lib
35
- ln -s usr/lib64
36
- ln -s usr/sbin
37
- '' ;
38
- copyToRoot = pkgs . buildEnv {
39
- name = "image-root" ;
40
- pathsToLink = [ "/" ] ;
41
- paths = [ ubuntu-cloudimg ] ;
42
- } ;
43
- config . Cmd = [ "/lib/systemd/systemd" ] ;
44
- } ;
45
-
46
7
dockerImageUbuntuWithTools =
47
8
let
48
9
tools = [ pkgs . ansible ] ;
52
13
tag = "0.1" ;
53
14
created = "now" ;
54
15
maxLayers = 30 ;
55
- fromImage = dockerImageUbuntu ;
16
+ fromImage = docker-image-ubuntu ;
17
+ compressor = "zstd" ;
56
18
config = {
57
19
Env = [
58
20
"PATH=${ lib . makeBinPath tools } :/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
@@ -69,19 +31,18 @@ pkgs.writeShellApplication {
69
31
requests
70
32
pytest
71
33
pytest-testinfra
34
+ pytest-xdist
72
35
rich
73
36
]
74
37
) )
75
38
] ;
76
39
text = ''
77
40
echo "Running Ansible tests..."
78
41
export DOCKER_IMAGE=${ dockerImageUbuntuWithTools . imageName } :${ dockerImageUbuntuWithTools . imageTag }
79
- if ! docker image inspect $DOCKER_IMAGE > /dev/null; then
80
- echo "Loading Docker image..."
81
- docker load < ${ dockerImageUbuntuWithTools }
82
- fi
83
- ANSIBLE_DIR=${ ../../ansible }
84
- pytest -p no:cacheprovider -s -v "$@" $ANSIBLE_DIR/tests --ansible-dir=$ANSIBLE_DIR --docker-image=$DOCKER_IMAGE
42
+ echo "Loading Docker image..."
43
+ docker load < ${ dockerImageUbuntuWithTools }
44
+ FLAKE_DIR=${ ../.. }
45
+ pytest -x -p no:cacheprovider -s -v "$@" $FLAKE_DIR/ansible/tests --flake-dir=$FLAKE_DIR --docker-image=$DOCKER_IMAGE
85
46
'' ;
86
47
meta = with pkgs . lib ; {
87
48
description = "Ansible test runner" ;
0 commit comments