%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/modules/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/modules/__pycache__/package_facts.cpython-39.opt-1.pyc

a

�)g�F�@sddlmZmZmZeZdZdZdZddl	Z	ddl
mZmZddl
mZmZddlmZdd	lmZdd
lmZmZmZddlmZmZmZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"dd�Z#e$dk�re#�dS)�)�absolute_import�division�print_functiona8
module: package_facts
short_description: Package information as facts
description:
  - Return information about installed packages as facts.
options:
  manager:
    description:
      - The package manager used by the system so we can query the package information.
      - Since 2.8 this is a list and can support multiple package managers per system.
      - The 'portage' and 'pkg' options were added in version 2.8.
      - The 'apk' option was added in version 2.11.
      - The 'pkg_info' option was added in version 2.13.
    default: ['auto']
    choices: ['auto', 'rpm', 'apt', 'portage', 'pkg', 'pacman', 'apk', 'pkg_info']
    type: list
    elements: str
  strategy:
    description:
      - This option controls how the module queries the package managers on the system.
        C(first) means it will return only information for the first supported package manager available.
        C(all) will return information for all supported and available package managers on the system.
    choices: ['first', 'all']
    default: 'first'
    type: str
    version_added: "2.8"
version_added: "2.5"
requirements:
    - For 'portage' support it requires the C(qlist) utility, which is part of 'app-portage/portage-utils'.
    - For Debian-based systems C(python-apt) package must be installed on targeted hosts.
    - For SUSE-based systems C(python3-rpm) package must be installed on targeted hosts.
      This package is required because SUSE does not include RPM Python bindings by default.
author:
  - Matthew Jones (@matburt)
  - Brian Coca (@bcoca)
  - Adam Miller (@maxamillion)
extends_documentation_fragment:
  -  action_common_attributes
  -  action_common_attributes.facts
attributes:
    check_mode:
        support: full
    diff_mode:
        support: none
    facts:
        support: full
    platform:
        platforms: posix
a�
- name: Gather the package facts
  ansible.builtin.package_facts:
    manager: auto

- name: Print the package facts
  ansible.builtin.debug:
    var: ansible_facts.packages

- name: Check whether a package called foobar is installed
  ansible.builtin.debug:
    msg: "{{ ansible_facts.packages['foobar'] | length }} versions of foobar are installed!"
  when: "'foobar' in ansible_facts.packages"

a�
ansible_facts:
  description: Facts to add to ansible_facts.
  returned: always
  type: complex
  contains:
    packages:
      description:
        - Maps the package name to a non-empty list of dicts with package information.
        - Every dict in the list corresponds to one installed version of the package.
        - The fields described below are present for all package managers. Depending on the
          package manager, there might be more fields for a package.
      returned: when operating system level package manager is specified or auto detected manager
      type: dict
      contains:
        name:
          description: The package's name.
          returned: always
          type: str
        version:
          description: The package's version.
          returned: always
          type: str
        source:
          description: Where information on the package came from.
          returned: always
          type: str
      sample: |-
        {
          "packages": {
            "kernel": [
              {
                "name": "kernel",
                "source": "rpm",
                "version": "3.10.0",
                ...
              },
              {
                "name": "kernel",
                "source": "rpm",
                "version": "3.10.0",
                ...
              },
              ...
            ],
            "kernel-tools": [
              {
                "name": "kernel-tools",
                "source": "rpm",
                "version": "3.10.0",
                ...
              }
            ],
            ...
          }
        }
        # Sample rpm
        {
          "packages": {
            "kernel": [
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel",
                "release": "514.26.2.el7",
                "source": "rpm",
                "version": "3.10.0"
              },
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel",
                "release": "514.16.1.el7",
                "source": "rpm",
                "version": "3.10.0"
              },
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel",
                "release": "514.10.2.el7",
                "source": "rpm",
                "version": "3.10.0"
              },
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel",
                "release": "514.21.1.el7",
                "source": "rpm",
                "version": "3.10.0"
              },
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel",
                "release": "693.2.2.el7",
                "source": "rpm",
                "version": "3.10.0"
              }
            ],
            "kernel-tools": [
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel-tools",
                "release": "693.2.2.el7",
                "source": "rpm",
                "version": "3.10.0"
              }
            ],
            "kernel-tools-libs": [
              {
                "arch": "x86_64",
                "epoch": null,
                "name": "kernel-tools-libs",
                "release": "693.2.2.el7",
                "source": "rpm",
                "version": "3.10.0"
              }
            ],
          }
        }
        # Sample deb
        {
          "packages": {
            "libbz2-1.0": [
              {
                "version": "1.0.6-5",
                "source": "apt",
                "arch": "amd64",
                "name": "libbz2-1.0"
              }
            ],
            "patch": [
              {
                "version": "2.7.1-4ubuntu1",
                "source": "apt",
                "arch": "amd64",
                "name": "patch"
              }
            ],
          }
        }
        # Sample pkg_info
        {
          "packages": {
            "curl": [
              {
                  "name": "curl",
                  "source": "pkg_info",
                  "version": "7.79.0"
              }
            ],
            "intel-firmware": [
              {
                  "name": "intel-firmware",
                  "source": "pkg_info",
                  "version": "20210608v0"
              }
            ],
          }
        }
N)�	to_native�to_text)�
AnsibleModule�missing_required_lib)�get_best_parsable_locale)�get_bin_path)�
has_respawned�probe_interpreters_for_module�respawn_module)�LibMgr�CLIMgr�get_all_pkg_managerscs0eZdZdZdd�Zdd�Z�fdd�Z�ZS)�RPM�rpmcCs|j����S�N)�_libZTransactionSetZdbMatch��self�r�A/usr/lib/python3.9/site-packages/ansible/modules/package_facts.py�list_installed�szRPM.list_installedcCs:t||jj||jj||jj||jj||jjd�S)N)�name�version�releaseZepoch�arch)�dictrZRPMTAG_NAMEZRPMTAG_VERSIONZRPMTAG_RELEASEZRPMTAG_EPOCHZRPMTAG_ARCH�r�packagerrr�get_package_detailss



�zRPM.get_package_detailscsttt|���}zNtd�|sBt�sBgd�}t||j�}|rBt|�|sZt�	dt
|j��WntynYn0|S)zh we expect the python bindings installed, but this gives warning if they are missing and we have rpm clir)z/usr/libexec/platform-python�/usr/bin/python3�/usr/bin/python2zFound "rpm" but %s)�superr�is_availabler
rr�LIBr
�module�warnr�
ValueError)r�we_have_lib�interpreters�interpreter_path��	__class__rrr%	s
zRPM.is_available)�__name__�
__module__�__qualname__r&rr!r%�
__classcell__rrr-rr�srcsHeZdZdZ�fdd�Zedd��Z�fdd�Zdd	�Zd
d�Z	�Z
S)�APT�aptcsd|_tt|���dSr)�_cacher$r3�__init__rr-rrr6&szAPT.__init__cCs"|jdur|jS|j��|_|jSr)r5rZCacherrrr�	pkg_cache*s
z
APT.pkg_cachec	s�tt|���}|s�dD]h}zt|�Wnty<YqYq0t�sdddg}t||j�}|rdt|�t	�
d|td�f�q�q|S)zi we expect the python bindings installed, but if there is apt/apt-get give warning about missing bindings)r4zapt-getZaptituder"r#zFound "%s" but %sr4)r$r3r%r
r)rrr&r
r'r(r)rr*Zexer+r,r-rrr%2s"
�zAPT.is_availablecs|j��fdd����D�S)Ncsg|]}�|jr|�qSr)Zis_installed)�.0Zpk��cacherr�
<listcomp>M�z&APT.list_installed.<locals>.<listcomp>)r7�keysrrr9rrJszAPT.list_installedcCs,|j|j}t||j|j|j|jdjd�S)Nr)rrr�category�origin)r7�	installedrrZarchitecture�sectionZoriginsr?)rr Zac_pkgrrrr!OszAPT.get_package_details)r/r0r1r&r6�propertyr7r%rr!r2rrr-rr3"s
r3c@s eZdZdZdd�Zdd�ZdS)�PACMANZpacmancCsVtt�}tj|jdgt|d�d�\}}}|dks4|rDtd||f��|�d�dd�S)Nz-Qi)�LC_ALL)Zenviron_updater�"Unable to list packages rc=%s : %sz

���)r	r'�run_command�_clir�	Exception�split)r�locale�rc�out�errrrrrXs
 zPACMAN.list_installedcCs�i}d}|��D]F}t�d|�}|r>|�d�}|�d�||<q||d|��||<qd}|ddkr�dd�|d�d�D�}|d	|d
|d|d�S)
Nz([\w ]*[\w]) +: (.*)��z  ZProvides�NonecSsg|]}|�d�d�qS)�=r)rJ)r8�prrrr;ns�z.PACMAN.get_package_details.<locals>.<listcomp>�NameZVersionZArchitecture)rrr�provides)�
splitlines�re�match�group�lstriprJ)rr �raw_pkg_detailsZlast_detail�line�mrUrrrr!_s$
��zPACMAN.get_package_detailsN�r/r0r1�CLIrr!rrrrrCTsrCc@s(eZdZdZgd�Zdd�Zdd�ZdS)�PKG�pkg)	rrr?r@�	automaticrr>�prefix�vitalc	CsJt�|jddd�gd��g�\}}}|dks2|rBtd||f��|��S)N�queryz%%%sz	%)	�n�v�R�t�a�q�orS�VrrE)r'rGrH�joinrIrV�rrLrMrNrrrr�s&zPKG.list_installedcCstt|j|�d���}d|vrLz|d�d�d|d<WntyJYn0d|vrhtt|d��|d<d|vr�|d�dd�d	|d<d
|vr�d|d
vr�|d
�dd�\|d
<|d<nd	|d<d
|d
vr�|d
�d
d�\|d
<|d<nd|d<d|v�rtt|d��|d<|S)N�	r�:rPrbr>�/rOrr�,Z
port_epoch�_Zrevision�0rd)r�zip�atomsrJ�
IndexError�bool�int)rr rarrrr!�s(
zPKG.get_package_detailsN�r/r0r1r_rwrr!rrrrr`{sr`c@s(eZdZdZgd�Zdd�Zdd�ZdS)�PORTAGEZqlist)r>rrZebuild_revision�slots�prefixesZsufixesc
CsNtjd�|jddddddg�dd	�\}}}|d
krFtd|t|�f��|��S)N� z-Iv�|Zxargsz-nZ1024ZqatomT)Zuse_unsafe_shellrrE)r'rGrnrH�RuntimeErrorrrVrorrrr�s*zPORTAGE.list_installedcCstt|j|����Sr)rrvrwrJrrrrr!�szPORTAGE.get_package_detailsNr{rrrrr|�sr|c@s eZdZdZdd�Zdd�ZdS)�APKZapkcCs<t�|jddg�\}}}|dks$|r4td||f��|��S)N�infoz-vrrE�r'rGrHrIrVrorrrr�szAPK.list_installedcCsN|ddd�}|�dd�}z|d|d|dd�WStyH|YS0dS)N�)rrr�-rPrrO)�rsplitrx)rr r[Znvrrrrr!�s�zAPK.get_package_detailsNr^rrrrr��sr�c@s eZdZdZdd�Zdd�ZdS)�PKG_INFOZpkg_infocCs:t�|jdg�\}}}|dks"|r2td||f��|��S)Nz-arrEr�rorrrr�szPKG_INFO.list_installedcCsT|dd�}|jdd�djddd�}z|d|dd�WStyN|YS0dS)Nr�)rrrO)�maxsplitrr�)rJr�rx)rr r[�detailsrrrr!�s
�zPKG_INFO.get_package_detailsNr^rrrrr��sr�c
Cst�}dd�|��D�}ttdddgd�ddgdd	�d
�dd�ai}d
ii}dd�tjdD�}tjd}d|vr�|�|�|�d�t|��	|�}|r�dtjdvr�d}ndd�
|�}tj|d�d}t�}	|D�]}
|r�|dkr��q�|
|	vr�q�|	�|
�z�z.||
�}|�
��r.|d7}|�|���WnZt�y�}z@|
tjdv�rht�d|
t|�f�WYd}~Wq�WYd}~n
d}~00Wq�t�y�}z2|
tjdv�r�t�d|
t|�f�WYd}~q�d}~00q�|dk�r�d|}tj|d�||d
d<tjfi|��dS)NcSsg|]}|���qSr��lower�r8�xrrrr;�r<zmain.<locals>.<listcomp>�list�str�auto)�type�elements�default�first�all)�choicesr�)�manager�strategyT)Z
argument_specZsupports_check_modeZ
ansible_factscSsg|]}|���qSrr�r�rrrr;�r<r�r�zKCould not auto detect a usable package manager, check warnings for details.z*Unsupported package managers requested: %sz, )�msgrrOz>Requested package manager %s was not usable by this module: %sz'Failed to retrieve packages with %s: %sz�Could not detect a supported package manager from the following list: %s, or the required Python library is not installed. Check warnings for details.�packages)rr=rrr'�params�extend�remove�set�
differencernZ	fail_json�addr%�updateZget_packagesrIr(rZ	exit_json)
ZPKG_MANAGERSZPKG_MANAGER_NAMESr��resultsZmanagersr�Zunsupportedr��found�seenZpkgmgrr��errr�main�s`��






(.
�r��__main__)%Z
__future__rrrr�Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrWZansible.module_utils._textrrZansible.module_utils.basicrrZ"ansible.module_utils.common.localer	Z#ansible.module_utils.common.processr
Z#ansible.module_utils.common.respawnrrr
Z#ansible.module_utils.facts.packagesrrrrr3rCr`r|r�r�r�r/rrrr�<module>s,2&'2',E


Zerion Mini Shell 1.0