Skip to content

Commit fe9bc47

Browse files
author
Ruud Peters
committed
initial ansible config
1 parent 9a5ff26 commit fe9bc47

File tree

8 files changed

+75
-6
lines changed

8 files changed

+75
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/dist
2+
*.retry

Dockerfile

+2-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ COPY --from=0 $BUILD_DIR/dist/ /app/
9696
# Install packages and build essentials
9797
ARG DEBIAN_FRONTEND="noninteractive"
9898
RUN apt-get update && apt install -y \
99-
ansible \
10099
build-essential \
101100
cmake \
102101
curl \
@@ -110,20 +109,16 @@ RUN apt-get update && apt install -y \
110109
ssh \
111110
sshpass \
112111
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1 \
113-
114112
# Install retry script
115113
&& curl $RETRY_SCRIPT -o /usr/local/bin/retry && chmod +x /usr/local/bin/retry \
116-
117114
# Build and install Qemu from source
118115
&& git clone --single-branch --branch $QEMU_BRANCH $QEMU_GIT $BUILD_DIR/qemu/ \
119116
&& mkdir $BUILD_DIR/qemu/build \
120117
&& (cd $BUILD_DIR/qemu/build && ../configure --target-list=aarch64-softmmu) \
121118
&& make -C $BUILD_DIR/qemu/build install -j$BUILD_CORES \
122119
&& rm -r $BUILD_DIR \
123-
124120
# Unzip distro image
125121
&& gunzip /app/distro.qcow2.gz \
126-
127122
# Start distro as daemon
128123
&& qemu-system-aarch64 \
129124
-M raspi3 \
@@ -152,12 +147,13 @@ RUN apt-get update && apt install -y \
152147
libpixman-1-dev \
153148
ninja-build \
154149
pkg-config \
150+
python3.8 \
155151
sshpass \
156152
# Stop the virtual machine
157153
&& sleep 20 \
158154
&& kill -15 $(pidof qemu-system-aarch64) \
159155
&& sleep 10 \
160-
# Finally compress the distro image
156+
# Compress distro image
161157
&& gzip /app/distro.qcow2
162158

163159
# Copy start script

test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
TEST_DIR="$(cd "$(dirname "$0")" && pwd)/test/"
3+
4+
ansible-playbook -i $TEST_DIR/hosts.yml $TEST_DIR/main.yml

test/host/start.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# This playbook prints a simple debug message
3+
- hosts: local
4+
connection: local
5+
tasks:
6+
- name: Start raspi machine
7+
docker_container:
8+
name: raspi
9+
image: ptrsr/rpi-qemu-kernel
10+
state: started
11+
network_mode: host
12+
# images:
13+
# - '../dist:/dist'
14+
15+
# Check machine connection
16+
- hosts: raspi
17+
gather_facts: no
18+
tasks:
19+
- name: Wait for machine startup
20+
wait_for_connection:
21+
timeout: 100

test/host/stop.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- hosts: raspi
3+
any_errors_fatal: false
4+
tasks:
5+
- name: Shutdown vm
6+
shell: shutdown now
7+
become: true
8+
async: 1
9+
poll: 0
10+
11+
- hosts: local
12+
connection: local
13+
tasks:
14+
- name: Wait for shutdown
15+
pause:
16+
seconds: 5
17+
18+
- name: Stop raspi container
19+
docker_container:
20+
name: raspi
21+
state: absent

test/hosts.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all:
2+
hosts:
3+
local:
4+
ansible_host: localhost
5+
raspi:
6+
ansible_host: localhost
7+
ansible_port: 2222
8+
ansible_ssh_user: pi
9+
ansible_ssh_pass: raspberry
10+
ansible_ssh_common_args: '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'

test/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# # Start raspi vm machine
3+
- import_playbook: host/start.yml
4+
5+
# # Execute tasks on raspi
6+
- import_playbook: raspi/test.yml
7+
8+
# Stop raspi vm machine
9+
- import_playbook: host/stop.yml

test/raspi/test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
# Print debug message in raspi machine
3+
- hosts: raspi
4+
tasks:
5+
- name: Print debug message
6+
debug:
7+
msg: Hello, world!

0 commit comments

Comments
 (0)