1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-04-27 11:28:48 +00:00

Update podman_image to specify CPU arch when pulling image (#578)

* Add test to sprcify CPU arch when pulling image

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Update to specify CPU arch when pulling image

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Add document for specifying arch

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Fix for idempotency

Signed-off-by: nishipy <goodisonev4@gmail.com>

* Update plugins/modules/podman_image.py

Signed-off-by: nishipy <goodisonev4@gmail.com>

---------

Signed-off-by: nishipy <goodisonev4@gmail.com>
This commit is contained in:
nishipy 2023-04-15 19:49:16 +09:00 committed by GitHub
parent e8c270370d
commit ab64d5f953
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 4 deletions

View file

@ -15,6 +15,10 @@ DOCUMENTATION = r'''
description:
- Build, pull, or push images using Podman.
options:
arch:
description:
- CPU architecutre for the container image
type: str
name:
description:
- Name of the image to pull, push, or delete. It may contain a tag using the format C(image:tag).
@ -267,6 +271,11 @@ EXAMPLES = r"""
- name: nginx
tag: 3
dest: docker.io/acme
- name: Pull an image for a specific CPU architecture
containers.podman.podman_image:
name: nginx
arch: amd64
"""
RETURN = r"""
@ -422,6 +431,7 @@ class PodmanImageManager(object):
self.ca_cert_dir = self.module.params.get('ca_cert_dir')
self.build = self.module.params.get('build')
self.push_args = self.module.params.get('push_args')
self.arch = self.module.params.get('arch')
repo, repo_tag = parse_repository_tag(self.name)
if repo_tag:
@ -526,9 +536,14 @@ class PodmanImageManager(object):
rc, images, err = self._run(args, ignore_errors=True)
images = json.loads(images)
if len(images) > 0:
return images
else:
return None
inspect_json = self.inspect_image(image_name)
if self._is_target_arch(inspect_json, self.arch) or not self.arch:
return images
return None
def _is_target_arch(self, inspect_json=None, arch=None):
return arch and inspect_json[0]['Architecture'] == arch
def find_image_id(self, image_id=None):
if image_id is None:
@ -560,6 +575,9 @@ class PodmanImageManager(object):
args = ['pull', image_name, '-q']
if self.arch:
args.extend(['--arch', self.arch])
if self.auth_file:
args.extend(['--authfile', self.auth_file])
@ -762,6 +780,7 @@ def main():
module = AnsibleModule(
argument_spec=dict(
name=dict(type='str', required=True),
arch=dict(type='str'),
tag=dict(type='str', default='latest'),
pull=dict(type='bool', default=True),
push=dict(type='bool', default=False),