diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e84b7353cf3..8c116a3ad24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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) diff --git a/templates/README.md b/templates/README.md index 585b49fac3a..26331b4363d 100644 --- a/templates/README.md +++ b/templates/README.md @@ -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) diff --git a/templates/ansible.yaml b/templates/ansible.yaml new file mode 100644 index 00000000000..94206a58cb0 --- /dev/null +++ b/templates/ansible.yaml @@ -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 + ------ diff --git a/templates/ansible/README.md b/templates/ansible/README.md new file mode 100644 index 00000000000..32aa6e261ef --- /dev/null +++ b/templates/ansible/README.md @@ -0,0 +1,9 @@ +# Ansible + +Playbook example from: + + + +Template example from: + + diff --git a/templates/ansible/playbook.yaml b/templates/ansible/playbook.yaml new file mode 100644 index 00000000000..ca42abb8001 --- /dev/null +++ b/templates/ansible/playbook.yaml @@ -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 diff --git a/templates/ansible/roles/hostname/tasks/main.yaml b/templates/ansible/roles/hostname/tasks/main.yaml new file mode 100644 index 00000000000..93319a802f9 --- /dev/null +++ b/templates/ansible/roles/hostname/tasks/main.yaml @@ -0,0 +1,5 @@ +--- +- name: write hostname using jinja2 + ansible.builtin.template: + src: templates/test.j2 + dest: /tmp/hostname diff --git a/templates/ansible/roles/hostname/templates/test.j2 b/templates/ansible/roles/hostname/templates/test.j2 new file mode 100644 index 00000000000..f7ac13743c7 --- /dev/null +++ b/templates/ansible/roles/hostname/templates/test.j2 @@ -0,0 +1 @@ +My name is {{ ansible_facts['hostname'] }}