Files
ayurishchevandClaude Opus 5.5 d0ab6b94f9 Ansible: deliver validator-agent from the artreg registry instead of building on each host
The role resolves image_tag to a digest once per run and pulls that image
on every validator before replacing the container; the git and build
steps are gone. scripts/publish-agent-image.sh builds and pushes the
agent image (<rev12> and latest tags).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 23:59:33 +03:00

55 lines
1.9 KiB
YAML

---
# Образ уже скачан: простой валидатора — только stop + rm + run.
- name: Create the config directory
ansible.builtin.file:
path: "{{ remote_env_file | dirname }}"
state: directory
owner: root
group: root
mode: "0700"
- name: Copy the env file to the validator
ansible.builtin.copy:
src: "{{ local_env_file }}"
dest: "{{ remote_env_file }}"
owner: root
group: root
mode: "0600"
no_log: true
- name: Check whether the container exists
ansible.builtin.command: "docker container inspect {{ container_name }}"
register: container_exists
changed_when: false
failed_when: false
- name: Stop the current container
ansible.builtin.command: "docker stop -t {{ stop_timeout }} {{ container_name }}"
when: container_exists.rc == 0
- name: Remove the current container
ansible.builtin.command: "docker rm -f {{ container_name }}"
when: container_exists.rc == 0
# --restart нужен: агент завершается, если регистрация в control-api не
# удалась, и должен подняться снова. validator_id берётся из inventory
# (validator_id) и перекрывает env-файл.
- name: Start the new container
ansible.builtin.command:
argv: >-
{{ ['docker', 'run', '-d',
'--name', container_name,
'--restart', restart_policy,
'--platform', platform,
'--env-file', remote_env_file,
'-e', 'VALIDATOR_AGENT_VALIDATOR_ID=' ~ effective_validator_id,
'--log-driver', 'json-file',
'--log-opt', 'max-size=' ~ log_max_size,
'--log-opt', 'max-file=' ~ log_max_file,
'--label', 'image.tag=' ~ image_tag,
'--label', 'image.digest=' ~ resolved_digest,
'--label', 'deployed.by=ansible']
+ (capabilities | map('regex_replace', '^(.*)$', '--cap-add=\1') | list)
+ [image_pull_ref] }}
register: started