74 lines
2.4 KiB
YAML
74 lines
2.4 KiB
YAML
---
|
|
- name: Crea cartella app
|
|
ansible.builtin.file:
|
|
path: /opt/application-consumption-demo-algorithm
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Render env file applicativo
|
|
ansible.builtin.template:
|
|
src: app.env.j2
|
|
dest: /opt/application-consumption-demo-algorithm/app.env
|
|
mode: '0600'
|
|
|
|
- name: Ferma eventuale container precedente
|
|
community.docker.docker_container:
|
|
name: "{{ container_name }}"
|
|
state: absent
|
|
|
|
- name: Calcola platform effettiva
|
|
ansible.builtin.set_fact:
|
|
effective_image_platform: >-
|
|
{{
|
|
(image_platform | default(''))
|
|
if (image_platform | default('')) != 'auto'
|
|
else
|
|
('linux/amd64' if ansible_architecture in ['x86_64', 'amd64']
|
|
else ('linux/arm64' if ansible_architecture in ['aarch64', 'arm64'] else ''))
|
|
}}
|
|
|
|
- name: Pull immagine primaria (digest o tag)
|
|
ansible.builtin.command: >-
|
|
docker pull{% if effective_image_platform | length > 0 %} --platform {{ effective_image_platform }}{% endif %} {{ container_image_ref }}
|
|
register: primary_pull
|
|
changed_when: primary_pull.rc == 0
|
|
failed_when: false
|
|
|
|
- name: Fallback pull tramite tag se digest non compatibile
|
|
ansible.builtin.command: >-
|
|
docker pull{% if effective_image_platform | length > 0 %} --platform {{ effective_image_platform }}{% endif %} {{ container_image }}:{{ image_tag }}
|
|
register: fallback_pull
|
|
changed_when: fallback_pull.rc == 0
|
|
failed_when: false
|
|
when:
|
|
- primary_pull.rc != 0
|
|
- image_digest | default('') | length > 0
|
|
|
|
- name: Valida esito pull immagine
|
|
ansible.builtin.assert:
|
|
that:
|
|
- primary_pull.rc == 0 or (fallback_pull is defined and fallback_pull.rc == 0)
|
|
fail_msg: >-
|
|
Pull fallito sia per {{ container_image_ref }} sia per {{ container_image }}:{{ image_tag }}
|
|
su platform {{ effective_image_platform | default('default') }}.
|
|
Verifica manifest compatibile con l'architettura host oppure pubblica immagine multi-arch.
|
|
|
|
- name: Seleziona riferimento immagine effettivo
|
|
ansible.builtin.set_fact:
|
|
pulled_image_ref: >-
|
|
{{
|
|
container_image_ref
|
|
if primary_pull.rc == 0
|
|
else (container_image ~ ':' ~ image_tag)
|
|
}}
|
|
|
|
- name: Avvia container ML app
|
|
community.docker.docker_container:
|
|
name: "{{ container_name }}"
|
|
image: "{{ pulled_image_ref }}"
|
|
state: started
|
|
restart_policy: unless-stopped
|
|
ports:
|
|
- "{{ app_port }}:5000"
|
|
env_file: /opt/application-consumption-demo-algorithm/app.env
|