
    Vh                     b    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d Zd Zed	k(  r e        yy)
    )absolute_importdivisionprint_functiona  
module: podman_search
author:
  - Derek Waters (@derekwaters)
short_description: Search for remote images using podman
notes:
  - Podman may required elevated privileges in order to run properly.
description:
  - Search for remote images using C(podman)
options:
  executable:
    description:
      - Path to C(podman) executable if it is not in the C($PATH) on the machine running C(podman)
    default: 'podman'
    type: str
  term:
    description:
      - The search term to look for. Will search all default registries unless a registry is defined in the search term.
    type: str
    required: True
  limit:
    description:
      - Limit the number of image results returned from the search (per image registry)
    required: False
    default: 25
    type: int
  list_tags:
    description:
      - Whether or not to return the list of tags associated with each image
    required: False
    default: False
    type: bool

a  
- name: Search for any rhel images
  containers.podman.podman_search:
    term: "rhel"
    limit: 3

- name: Gather info on a specific remote image
  containers.podman.podman_search:
    term: "myimageregistry.com/ansible-automation-platform/ee-minimal-rhel8"

- name: Gather tag info on a known remote image
  containers.podman.podman_search:
    term: "myimageregistry.com/ansible-automation-platform/ee-minimal-rhel8"
    list_tags: True
a  
images:
    description: info from all or specified images
    returned: always
    type: list
    sample: [
        {
            "Automated": "",
            "Description": "Red Hat Enterprise Linux Atomic Image is a minimal, fully supported base image.",
            "Index": "registry.access.redhat.com",
            "Name": "registry.access.redhat.com/rhel7-atomic",
            "Official": "",
            "Stars": 0,
            "Tags": ["1.0", "1.1", "1.1.1-devel"]
        }
    ]
N)AnsibleModulec                 $   |d|ddg}|j                  ddj                  |      g       |r|j                  dg       | j                  |      \  }}}|dk7  r|r|dk(  rd	|v r||fS |dk7  r"| j                  d
j                  ||             ||fS )Nsearchz--formatjsonz--limitz{0}z--list-tagsr    zfetching tags listz$Unable to gather info for '{0}': {1}msg)extendformatrun_command	fail_json)	module
executabletermlimit	list_tagscommandrcouterrs	            s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/containers/podman/plugins/modules/podman_search.pysearch_imagesr   S   s    8T:v>GNNIu||E234'%%g.LBS	Qw9/Cs/JCx	QwCJJ4QTUV8O    c                     t        t        t        dd      t        dd      t        ddd	      t        d
dd	            d      } | j                  d   }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j	                  |d      }t        | ||||      \  }}|dk(  rg }n	 t        j                  |      }t        d|      } | j                  di | y # t        j                  j                  $ r% | j                  dj                  |             Y bw xY w)Nstrpodman)typedefaultT)r    requiredintF   )r    r"   r!   bool)r   r   r   r   )argument_specsupports_check_moder   r   r   r   )r"   r
   z5Failed to parse JSON output from podman search: {out})r   r   )changedimagesstderr )r   dictparamsgetget_bin_pathr   r	   loadsdecoderJSONDecodeErrorr   r   	exit_json)r   r   r   r   r   
result_strerrorsresultss           r   mainr7   a   sF   9540EE2>F	
 !F |,J==V$DMMg&E!!+.I$$Z$$?J&vz4	RJR	qjj,G G Fw ||++ 	q!X!_!_dn!_!op	qs   D ?EE__main__)
__future__r   r   r   r    __metaclass__DOCUMENTATIONEXAMPLESRETURNr	   ansible.module_utils.basicr   r   r7   __name__r+   r   r   <module>r@      sP   
 A @!F 
$  4  F zF r   