Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example of ansible provisioning with playbook #2676

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
run: sudo make install
- name: Verify templates match `limactl edit` format
run: |
find templates -name '*.yaml' -exec limactl edit --set 'del(.nothing)' {} \;
find templates -name '*.yaml' -not \( -path "templates/ansible/*" -prune \) -exec limactl edit --set 'del(.nothing)' {} \;
git diff-index --exit-code HEAD
- name: Uninstall
run: sudo make uninstall
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
- name: Validate jsonschema
run: make schema-limayaml.json
- name: Validate templates
run: find -L templates -name '*.yaml' | xargs limactl validate
run: find -L templates -name '*.yaml' -not \( -path "templates/ansible/*" -prune \) | xargs limactl validate
- name: Install test dependencies
# QEMU: required by Lima itself
# bash: required by test-templates.sh (OS version of bash is too old)
Expand Down
3 changes: 3 additions & 0 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ Distro:
- [`experimental/opensuse-tumbleweed`](./experimental/opensuse-tumbleweed.yaml): [experimental] openSUSE Tumbleweed
- [`experimental/debian-sid`](./experimental/debian-sid.yaml): [experimental] Debian Sid

Provisioning:
- [`ansible`](./ansible.yaml): Ansible, using [playbook.yaml](./ansible/playbook.yaml)

Container engines:
- [`apptainer`](./apptainer.yaml): Apptainer
- [`apptainer-rootful`](./apptainer-rootful.yaml): Apptainer (rootful)
Expand Down
31 changes: 31 additions & 0 deletions templates/ansible.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
minimumLimaVersion: "1.0.0"
images:
# Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
- location: "https://cloud-images.ubuntu.com/releases/noble/release-20250313/ubuntu-24.04-server-cloudimg-amd64.img"
arch: "x86_64"
digest: "sha256:eacac65efe9e9bae0cbcb3f9d5c2b5e8c5313fa78a3bc401c3fb28b2d48cefc0"
- location: "https://cloud-images.ubuntu.com/releases/noble/release-20250313/ubuntu-24.04-server-cloudimg-arm64.img"
arch: "aarch64"
digest: "sha256:103f31c5a5b7f031a60ce3555c8fbd56317fd8ffbaaa7e17002879e6157d546d"
# Fallback to the latest release image.
# Hint: run `limactl prune` to invalidate the cache
- location: "https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-amd64.img"
arch: "x86_64"
- location: "https://cloud-images.ubuntu.com/releases/noble/release/ubuntu-24.04-server-cloudimg-arm64.img"
arch: "aarch64"
mounts:
- location: "~"
- location: "/tmp/lima"
writable: true

provision:
- mode: ansible
playbook: ./templates/ansible/playbook.yaml
message: |
To run `ansible` on the host (assumes ansible is installed), run the following commands:
------
export ANSIBLE_INVENTORY="{{.Dir}}/ansible-inventory.yaml"
# To see the inventory: `ansible-inventory --list --yaml`

ansible all -m ping
------
9 changes: 9 additions & 0 deletions templates/ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ansible

Playbook example from:

<https://docs.ansible.com/ansible/latest/getting_started/get_started_playbook.html>

Template example from:

<https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_templating.html>
11 changes: 11 additions & 0 deletions templates/ansible/playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: My first play
hosts: all
tasks:
- name: Ping my hosts
ansible.builtin.ping:

- name: Print message
ansible.builtin.debug:
msg: Hello world
roles:
- hostname
5 changes: 5 additions & 0 deletions templates/ansible/roles/hostname/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- name: write hostname using jinja2
ansible.builtin.template:
src: templates/test.j2
dest: /tmp/hostname
1 change: 1 addition & 0 deletions templates/ansible/roles/hostname/templates/test.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
My name is {{ ansible_facts['hostname'] }}
Loading