Skip to content

Commit 775c05a

Browse files
committed
Add example of ansible provisioning with playbook
Currently the playbook is relative to the current workdir, it should probably be relative to the lima.yaml instead. The YAML syntax and the directory layout has been modified slightly from the original, to work with Lima's setup. Signed-off-by: Anders F Björklund <[email protected]>
1 parent 0625d0b commit 775c05a

File tree

7 files changed

+62
-2
lines changed

7 files changed

+62
-2
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
run: sudo make install
123123
- name: Verify templates match `limactl edit` format
124124
run: |
125-
find templates -name '*.yaml' -exec limactl edit --set 'del(.nothing)' {} \;
125+
find templates -name '*.yaml' -not \( -path "templates/ansible/*" -prune \) -exec limactl edit --set 'del(.nothing)' {} \;
126126
git diff-index --exit-code HEAD
127127
- name: Uninstall
128128
run: sudo make uninstall
@@ -196,7 +196,7 @@ jobs:
196196
- name: Validate jsonschema
197197
run: make schema-limayaml.json
198198
- name: Validate templates
199-
run: find -L templates -name '*.yaml' | xargs limactl validate
199+
run: find -L templates -name '*.yaml' -not \( -path "templates/ansible/*" -prune \) | xargs limactl validate
200200
- name: Install test dependencies
201201
# QEMU: required by Lima itself
202202
# bash: required by test-templates.sh (OS version of bash is too old)

templates/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ Distro:
3232
- [`experimental/opensuse-tumbleweed`](./experimental/opensuse-tumbleweed.yaml): [experimental] openSUSE Tumbleweed
3333
- [`experimental/debian-sid`](./experimental/debian-sid.yaml): [experimental] Debian Sid
3434

35+
Provisioning:
36+
- [`ansible`](./ansible.yaml): Ansible, using [playbook.yaml](./ansible/playbook.yaml)
37+
3538
Container engines:
3639
- [`apptainer`](./apptainer.yaml): Apptainer
3740
- [`apptainer-rootful`](./apptainer-rootful.yaml): Apptainer (rootful)

templates/ansible.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
minimumLimaVersion: "1.0.0"
2+
images:
3+
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
4+
- location: "https://cloud-images.ubuntu.com/releases/noble/release-20250313/ubuntu-24.04-server-cloudimg-amd64.img"
5+
arch: "x86_64"
6+
digest: "sha256:eacac65efe9e9bae0cbcb3f9d5c2b5e8c5313fa78a3bc401c3fb28b2d48cefc0"
7+
- location: "https://cloud-images.ubuntu.com/releases/noble/release-20250313/ubuntu-24.04-server-cloudimg-arm64.img"
8+
arch: "aarch64"
9+
digest: "sha256:103f31c5a5b7f031a60ce3555c8fbd56317fd8ffbaaa7e17002879e6157d546d"
10+
# Fallback to the latest release image.
11+
# Hint: run `limactl prune` to invalidate the cache
12+
- location: "https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-amd64.img"
13+
arch: "x86_64"
14+
- location: "https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-arm64.img"
15+
arch: "aarch64"
16+
mounts:
17+
- location: "~"
18+
- location: "/tmp/lima"
19+
writable: true
20+
21+
provision:
22+
- mode: ansible
23+
playbook: ./templates/ansible/playbook.yaml
24+
message: |
25+
To run `ansible` on the host (assumes ansible is installed), run the following commands:
26+
------
27+
export ANSIBLE_INVENTORY="{{.Dir}}/ansible-inventory.yaml"
28+
# To see the inventory: `ansible-inventory --list --yaml`
29+
30+
ansible all -m ping
31+
------

templates/ansible/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Ansible
2+
3+
Playbook example from:
4+
5+
<https://docs.ansible.com/ansible/latest/getting_started/get_started_playbook.html>
6+
7+
Template example from:
8+
9+
<https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_templating.html>

templates/ansible/playbook.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- name: My first play
2+
hosts: all
3+
tasks:
4+
- name: Ping my hosts
5+
ansible.builtin.ping:
6+
7+
- name: Print message
8+
ansible.builtin.debug:
9+
msg: Hello world
10+
roles:
11+
- hostname
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: write hostname using jinja2
3+
ansible.builtin.template:
4+
src: templates/test.j2
5+
dest: /tmp/hostname
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
My name is {{ ansible_facts['hostname'] }}

0 commit comments

Comments
 (0)