Skip to content

Commit 3fbb14f

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 <anders.f.bjorklund@gmail.com>
1 parent 0625d0b commit 3fbb14f

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

templates/README.md

Lines changed: 3 additions & 0 deletions
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

Lines changed: 31 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 11 additions & 0 deletions
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
Lines changed: 5 additions & 0 deletions
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
My name is {{ ansible_facts['hostname'] }}

0 commit comments

Comments
 (0)