Files
ilnmors-homelab/ansible/roles/app/tasks/services/set_stablediffusion.yaml
T
2026-09-09 23:13:28 +09:00

92 lines
3.3 KiB
YAML

---
- name: Check model directory in data volume
ansible.builtin.find:
path: "{{ node['home_path'] }}/data/containers/stablediffusion/models"
file_type: "file"
patterns:
- "*.gguf"
- "*.safetensors"
hidden: true
recurse: true
register: stablediffusion_models
- name: Failure when models directory in data volume
ansible.builtin.fail:
msg: "There are no models in data directory, please ensure download some model files for stable-diffusion.cpp"
when: stablediffusion_models.matched == 0
- name: Create stablediffusion directory
ansible.builtin.file:
path: "{{ node['home_path'] }}/{{ item }}"
state: "directory"
owner: "{{ ansible_user }}"
group: "{{ node['group'] }}"
mode: "0770"
loop:
- "containers/stablediffusion"
- "containers/stablediffusion/models"
- name: Sync model data (--delete=true)
delegate_to: "{{ inventory_hostname }}"
ansible.posix.synchronize:
src: "{{ node['home_path'] }}/data/containers/stablediffusion/models/"
dest: "{{ node['home_path'] }}/containers/stablediffusion/models/"
owner: true
group: true
perms: true
delete: true
notify: "notification_restart_stablediffusion"
- name: Set active model
ansible.builtin.set_fact:
stabeldiffusion_active_model: "{{ services['stablediffusion']['dependency']['models']['active'] }}"
- name: Pull image
containers.podman.podman_image:
name: "ghcr.io/leejet/stable-diffusion.cpp"
tag: "{{ version['containers']['stablediffusion'] }}"
state: "present"
pull: true
- name: Deploy container file
ansible.builtin.template:
src: "{{ hostvars['console']['node']['config_path'] }}/services/containers/app/stablediffusion/stablediffusion.container.j2"
dest: "{{ node['home_path'] }}/.config/containers/systemd/stablediffusion.container"
owner: "{{ ansible_user }}"
group: "{{ node['group'] }}"
mode: "0644"
notify: "notification_restart_stablediffusion"
- name: Enable stablediffusion.service
ansible.builtin.systemd:
name: "stablediffusion.service"
state: "started"
enabled: true
daemon_reload: true
scope: "user"
- name: Set stable-diffusion archive version
ansible.builtin.set_fact:
stablediffusion_archive_version: >-
{{ version['containers']['stablediffusion'].split('@sha256:')[0] }}@{{ version['containers']['stablediffusion'].split('@sha256:')[1][0:7] }}
- name: Check container archive images
ansible.builtin.stat:
path: "{{ node['home_path'] }}/archives/containers/ghcr.io_leejet_stable-diffusion.cpp_{{ stablediffusion_archive_version }}.tar"
register: container_archive_images
- name: Save container archive images
containers.podman.podman_save:
image:
- "ghcr.io/leejet/stable-diffusion.cpp:{{ version['containers']['stablediffusion'] }}"
dest: "{{ node['home_path'] }}/archives/containers/ghcr.io_leejet_stable-diffusion.cpp_{{ stablediffusion_archive_version }}.tar"
format: "oci-archive"
force: false
when: not container_archive_images.stat.exists
- name: Fetch container archive images
ansible.builtin.fetch:
src: "{{ node['home_path'] }}/archives/containers/ghcr.io_leejet_stable-diffusion.cpp_{{ stablediffusion_archive_version }}.tar"
dest: "{{ hostvars['console']['node']['data_path'] }}/images/containers/"
flat: true