Skip to content

[Cherry-pick 202503] ansible: support pulling ceos_image from docker registry#1082

Open
wangxinbot wants to merge 1 commit intoAzure:202503from
wangxinbot:cherry-pick-22794-msft-202503
Open

[Cherry-pick 202503] ansible: support pulling ceos_image from docker registry#1082
wangxinbot wants to merge 1 commit intoAzure:202503from
wangxinbot:cherry-pick-22794-msft-202503

Conversation

@wangxinbot
Copy link

Cherry-pick of sonic-net/sonic-mgmt#22794 to 202503 branch.

Original PR: sonic-net/sonic-mgmt#22794

Conflicts resolved in ansible/roles/vm_set/tasks/add_ceos_list.yml.

What is the motivation for this PR?
In environments that enforce registry-only container image policies (e.g. Microsoft requiring all images to originate from ACR or MCR), the previous approach of building ceos_image locally or re-tagging a pulled image with a local name would trigger security alerts. This PR allows ceos_image to be sourced directly from a user-configured registry, so containers always reference the registry-prefixed image name and no locally-built alias is created.

How did you do it?
Three files are changed:

ansible/group_vars/vm_host/ceos.yml

Added three commented-out placeholder variables: ceos_registry, ceos_registry_username, ceos_registry_password.
When ceos_registry is uncommented and set, the new registry logic is activated. Credentials are optional and only needed for authenticated registries.
ansible/roles/vm_set/tasks/add_ceos_list.yml

When ceos_registry is defined, check whether <registry>/<ceos_image> is already cached locally (a prior pull). If found, it is used directly — no docker tag is performed, so no local alias is created.
If not cached and ceos_registry is defined, optionally log in (only when credentials are provided) and docker pull the image.
Only falls back to the existing download-ceos_image_orig-and-build path when registry is not configured or the pull fails.
ceos_image_found logic is registry-aware: when ceos_registry is defined, a plain local ceos_image does not count as "found", ensuring the registry path is always taken.
ansible/roles/eos/tasks/ceos.yml and ceos_ensure_reachable.yml

After loading group_vars/vm_host/ceos.yml, a docker_image_info check determines whether the registry image is available locally.
ceos_effective_image is set to <registry>/<ceos_image> when the registry image is present, or plain ceos_image otherwise.
All docker_container tasks use ceos_effective_image instead of ceos_image, so containers always reference the registry image in registry-enabled environments.
How did you verify/test it?
Tested "add-topo" by specifying ceos_registry. The ceos image from the registry is used successfully.
Tested "add-topo" without specifying ceos_registry. The existing logic of using a local ceos image or preparing ceos image from ceos_image_orig works as expected.

Signed-off-by: Xin Wang <[email protected]>
Co-authored-by: Copilot <[email protected]>
@wangxinbot
Copy link
Author

@microsoft-github-policy-service agree company="Microsoft"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants