|
22 | 22 |
|
23 | 23 | # List of tasks to execute in order |
24 | 24 | tasks: |
25 | | - # Task 1: Update package cache |
| 25 | + # Task 0: Network diagnostics for CI troubleshooting |
| 26 | + - name: Check network connectivity and DNS resolution |
| 27 | + ansible.builtin.shell: | |
| 28 | + echo "=== Network Diagnostics ===" |
| 29 | + echo "Testing DNS resolution..." |
| 30 | + nslookup archive.ubuntu.com || echo "DNS resolution failed" |
| 31 | + echo "Testing connectivity to Ubuntu repositories..." |
| 32 | + curl -I https://archive.ubuntu.com/ubuntu/ --connect-timeout 10 || echo "Ubuntu repo unreachable" |
| 33 | + echo "Testing connectivity to Docker repositories..." |
| 34 | + curl -I https://download.docker.com --connect-timeout 10 || echo "Docker repo unreachable" |
| 35 | + echo "Current apt sources:" |
| 36 | + cat /etc/apt/sources.list |
| 37 | + register: network_diagnostics |
| 38 | + changed_when: false |
| 39 | + ignore_errors: true |
| 40 | + |
| 41 | + - name: Display network diagnostics |
| 42 | + ansible.builtin.debug: |
| 43 | + var: network_diagnostics.stdout_lines |
| 44 | + when: network_diagnostics is defined |
| 45 | + |
| 46 | + # Task 1: Update package cache with retries and better error handling |
26 | 47 | - name: Update apt package cache |
27 | 48 | ansible.builtin.apt: |
28 | 49 | update_cache: true |
29 | 50 | cache_valid_time: 3600 # Cache valid for 1 hour |
| 51 | + force_apt_get: true # Force using apt-get instead of aptitude for better CI compatibility |
| 52 | + register: apt_update_result |
| 53 | + retries: 3 |
| 54 | + delay: 10 |
| 55 | + until: apt_update_result is succeeded |
30 | 56 | when: ansible_os_family == "Debian" |
31 | | - |
32 | | - # Task 2: Install required packages for Docker repository |
| 57 | + ignore_errors: false # Fail if apt update ultimately fails |
| 58 | + |
| 59 | + # Task 1.1: Fallback apt update with different approach if needed |
| 60 | + - name: Fallback apt update with apt-get directly |
| 61 | + ansible.builtin.command: apt-get update |
| 62 | + register: apt_get_update |
| 63 | + retries: 2 |
| 64 | + delay: 15 |
| 65 | + until: apt_get_update.rc == 0 |
| 66 | + when: |
| 67 | + - ansible_os_family == "Debian" |
| 68 | + - apt_update_result is failed |
| 69 | + ignore_errors: false |
| 70 | + |
| 71 | + # Task 2: Install required packages for Docker repository with retries |
33 | 72 | - name: Install required packages for Docker repository |
34 | 73 | ansible.builtin.apt: |
35 | 74 | name: |
|
39 | 78 | - gnupg |
40 | 79 | - lsb-release |
41 | 80 | state: present |
| 81 | + force_apt_get: true |
| 82 | + register: prereq_packages |
| 83 | + retries: 3 |
| 84 | + delay: 10 |
| 85 | + until: prereq_packages is succeeded |
42 | 86 | when: ansible_os_family == "Debian" |
43 | 87 |
|
44 | 88 | # Task 3: Add Docker's official GPG key |
|
57 | 101 | filename: docker |
58 | 102 | when: ansible_os_family == "Debian" |
59 | 103 |
|
60 | | - # Task 5: Update package cache after adding repository |
| 104 | + # Task 5: Update package cache after adding repository with retries |
61 | 105 | - name: Update apt package cache after adding Docker repository |
62 | 106 | ansible.builtin.apt: |
63 | 107 | update_cache: true |
| 108 | + force_apt_get: true # Force using apt-get for better CI compatibility |
| 109 | + register: apt_update_docker_repo |
| 110 | + retries: 3 |
| 111 | + delay: 10 |
| 112 | + until: apt_update_docker_repo is succeeded |
64 | 113 | when: ansible_os_family == "Debian" |
65 | 114 |
|
66 | | - # Task 6: Install Docker packages |
| 115 | + # Task 6: Install Docker packages with retries |
67 | 116 | - name: Install Docker packages |
68 | 117 | ansible.builtin.apt: |
69 | 118 | name: |
|
72 | 121 | - containerd.io |
73 | 122 | - docker-buildx-plugin |
74 | 123 | state: present |
| 124 | + force_apt_get: true |
| 125 | + register: docker_install |
| 126 | + retries: 3 |
| 127 | + delay: 10 |
| 128 | + until: docker_install is succeeded |
75 | 129 | when: ansible_os_family == "Debian" |
76 | 130 |
|
77 | 131 | # Task 7: Start and enable Docker service |
|
0 commit comments