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 2 commits 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
3 changes: 3 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions examples/ansible.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 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
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 examples/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 examples/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 examples/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 examples/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