From 587ff3e8292bde28770ccd56637a5254338b56f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Wed, 2 Oct 2024 18:48:33 +0200 Subject: [PATCH 1/2] Add example of ansible provisioning with playbook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- examples/README.md | 3 +++ examples/ansible.yaml | 24 +++++++++++++++++++ examples/ansible/README.md | 9 +++++++ examples/ansible/playbook.yaml | 11 +++++++++ .../ansible/roles/hostname/tasks/main.yaml | 5 ++++ .../ansible/roles/hostname/templates/test.j2 | 1 + 6 files changed, 53 insertions(+) create mode 100644 examples/ansible.yaml create mode 100644 examples/ansible/README.md create mode 100644 examples/ansible/playbook.yaml create mode 100644 examples/ansible/roles/hostname/tasks/main.yaml create mode 100644 examples/ansible/roles/hostname/templates/test.j2 diff --git a/examples/README.md b/examples/README.md index aa1b5ecb12e..81e37c591a1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -29,6 +29,9 @@ Distro: - [`experimental/gentoo`](./experimental/gentoo.yaml): [experimental] Gentoo - [`experimental/opensuse-tumbleweed`](./experimental/opensuse-tumbleweed.yaml): [experimental] openSUSE Tumbleweed +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/examples/ansible.yaml b/examples/ansible.yaml new file mode 100644 index 00000000000..b0aca136dab --- /dev/null +++ b/examples/ansible.yaml @@ -0,0 +1,24 @@ +# This template requires Lima v0.7.0 or later. +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/24.04/release-20240821/ubuntu-24.04-server-cloudimg-amd64.img" + arch: "x86_64" + digest: "sha256:0e25ca6ee9f08ec5d4f9910054b66ae7163c6152e81a3e67689d89bd6e4dfa69" +- location: "https://cloud-images.ubuntu.com/releases/24.04/release-20240821/ubuntu-24.04-server-cloudimg-arm64.img" + arch: "aarch64" + digest: "sha256:5ecac6447be66a164626744a87a27fd4e6c6606dc683e0a233870af63df4276a" +# Fallback to the latest release image. +# Hint: run `limactl prune` to invalidate the cache +- location: "https://cloud-images.ubuntu.com/releases/24.04/release/ubuntu-24.04-server-cloudimg-amd64.img" + arch: "x86_64" +- location: "https://cloud-images.ubuntu.com/releases/24.04/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 diff --git a/examples/ansible/README.md b/examples/ansible/README.md new file mode 100644 index 00000000000..32aa6e261ef --- /dev/null +++ b/examples/ansible/README.md @@ -0,0 +1,9 @@ +# Ansible + +Playbook example from: + + + +Template example from: + + diff --git a/examples/ansible/playbook.yaml b/examples/ansible/playbook.yaml new file mode 100644 index 00000000000..ca42abb8001 --- /dev/null +++ b/examples/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/examples/ansible/roles/hostname/tasks/main.yaml b/examples/ansible/roles/hostname/tasks/main.yaml new file mode 100644 index 00000000000..93319a802f9 --- /dev/null +++ b/examples/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/examples/ansible/roles/hostname/templates/test.j2 b/examples/ansible/roles/hostname/templates/test.j2 new file mode 100644 index 00000000000..f7ac13743c7 --- /dev/null +++ b/examples/ansible/roles/hostname/templates/test.j2 @@ -0,0 +1 @@ +My name is {{ ansible_facts['hostname'] }} From a789c5f3d0712840a4583c5c1b893fd6c5e2ce40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Thu, 3 Oct 2024 11:58:48 +0200 Subject: [PATCH 2/2] Add message on how to access ansible inventory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Anders F Björklund --- examples/ansible.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/ansible.yaml b/examples/ansible.yaml index b0aca136dab..dc875a2e75e 100644 --- a/examples/ansible.yaml +++ b/examples/ansible.yaml @@ -22,3 +22,11 @@ mounts: 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 + ------