Debian Codegraph @

ansible_collections/containers/podman/playbooks/examples/build_ai_env_with_ansible.yml

raw
1 ---
2 - name: Build a consistent AI dev environment image using Ansible and Buildah connection
3 hosts: localhost
4 gather_facts: false
5 vars:
6 base_image: "python:3.11-slim"
7 image_name: "ai-dev-env:latest"
8 workdir: "/workspace"
9 tasks:
10 - name: Start Buildah working container
11 command: buildah from {{ base_image }}
12 register: from_out
13
14 - set_fact:
15 container_id: "{{ from_out.stdout | trim }}"
16
17 - name: Configure working directory
18 command: buildah config --workingdir {{ workdir }} {{ container_id }}
19
20 - name: Add working container as dynamic host (Buildah connection)
21 add_host:
22 name: "buildcntr_{{ container_id }}"
23 ansible_connection: containers.podman.buildah
24 ansible_host: "{{ container_id }}"
25 ansible_buildah_working_directory: "{{ workdir }}"
26
27 - name: Provision AI environment inside container using role
28 import_role:
29 name: ai-dev-env
30 delegate_to: "buildcntr_{{ container_id }}"
31
32 - name: Set container metadata
33 shell: |
34 buildah config --env "JUPYTER_TOKEN=ansible" {{ container_id }}
35 buildah config --port 8888 {{ container_id }}
36 buildah config --cmd "jupyter lab --ip=0.0.0.0 --no-browser" {{ container_id }}
37
38 - name: Commit image
39 command: buildah commit {{ container_id }} {{ image_name }}
40
41