fix: use shell command for docker pull to get better error messages
Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Successful in 30s
Security Vulnerability Scan / Check for Dependency Changes (push) Successful in 23s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Successful in 11s
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
Security Vulnerability Scan / Composer Security Audit (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Successful in 12s
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Failing after 11m15s
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been cancelled

- Replace docker_image module with shell command for more reliable pulling
- Add detailed error output from pull command (stdout/stderr)
- Show actual docker pull error messages when pull fails
- Simplify pull logic - always attempt pull regardless of local existence
This commit is contained in:
2025-11-09 00:57:08 +01:00
parent bfcaf09936
commit 03affc87cf

View File

@@ -144,36 +144,30 @@
changed_when: false changed_when: false
failed_when: false failed_when: false
- name: Pull Docker image (force pull if not exists locally) - name: Display image existence check
community.docker.docker_image: ansible.builtin.debug:
name: "{{ deploy_image }}" msg:
source: pull - "Image exists before pull: {{ image_exists_before_pull.stdout | default('unknown') }}"
pull: always - "Will pull: {{ 'YES' if (image_exists_before_pull.stdout | default('') == 'NOT_FOUND') else 'NO (already exists)' }}"
when: when: registry_accessible is defined and registry_accessible == 'true'
- registry_accessible is defined and registry_accessible == 'true'
- image_exists_before_pull.stdout | default('') == 'NOT_FOUND'
register: image_pull_result
ignore_errors: yes
failed_when: false
- name: Pull Docker image (if already exists, just verify) - name: Pull Docker image from registry using shell command
community.docker.docker_image: ansible.builtin.shell: |
name: "{{ deploy_image }}" docker pull {{ deploy_image }} 2>&1
source: pull
pull: true
when: when:
- registry_accessible is defined and registry_accessible == 'true' - registry_accessible is defined and registry_accessible == 'true'
- image_exists_before_pull.stdout | default('') != 'NOT_FOUND'
register: image_pull_result register: image_pull_result
ignore_errors: yes ignore_errors: yes
failed_when: false failed_when: false
changed_when: image_pull_result.rc == 0
- name: Display pull result - name: Display pull result
ansible.builtin.debug: ansible.builtin.debug:
msg: msg:
- "Pull result: {{ image_pull_result | default('not executed') }}" - "Pull command exit code: {{ image_pull_result.rc | default('unknown') }}"
- "Pull failed: {{ image_pull_result.failed | default(false) }}" - "Pull stdout: {{ image_pull_result.stdout | default('none') }}"
- "Pull changed: {{ image_pull_result.changed | default(false) }}" - "Pull stderr: {{ image_pull_result.stderr | default('none') }}"
- "Pull succeeded: {{ 'YES' if (image_pull_result.rc | default(1) == 0) else 'NO' }}"
when: registry_accessible is defined and registry_accessible == 'true' when: registry_accessible is defined and registry_accessible == 'true'
- name: Verify image exists locally after pull - name: Verify image exists locally after pull
@@ -205,11 +199,19 @@
msg: | msg: |
Failed to pull image {{ deploy_image }} from registry. Failed to pull image {{ deploy_image }} from registry.
The image does not exist locally after pull attempt. The image does not exist locally after pull attempt.
Pull result: changed={{ image_pull_result.changed | default(false) }}, failed={{ image_pull_result.failed | default(false) }}
Pull command result:
- Exit code: {{ image_pull_result.rc | default('unknown') }}
- Stdout: {{ image_pull_result.stdout | default('none') }}
- Stderr: {{ image_pull_result.stderr | default('none') }}
Image check result: {{ image_check.stdout | default('unknown') }}
Please check: Please check:
1. Does the image exist in {{ source_registry }}? 1. Does the image exist in {{ source_registry }}?
2. Are registry credentials correct? 2. Are registry credentials correct?
3. Is the registry accessible? 3. Is the registry accessible?
4. Check the pull command output above for specific error messages.
when: when:
- registry_accessible is defined and registry_accessible == 'true' - registry_accessible is defined and registry_accessible == 'true'
- (image_check.stdout | default('') == 'NOT_FOUND' or image_check.stdout | default('') == '') - (image_check.stdout | default('') == 'NOT_FOUND' or image_check.stdout | default('') == '')