
    Vh                         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 dlmZ d dlmZ  e	j                  d	      Z e	j                  d
      Z G d d      Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionaH  
module: yum_versionlock
version_added: 2.0.0
short_description: Locks / unlocks a installed package(s) from being updated by yum package manager
description:
  - This module adds installed packages to yum versionlock to prevent the package(s) from being updated.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    description:
      - Package name or a list of package names with optional version or wildcards.
      - Specifying versions is supported since community.general 7.2.0.
    type: list
    required: true
    elements: str
  state:
    description:
      - If state is V(present), package(s) is/are added to yum versionlock list.
      - If state is V(absent), package(s) is/are removed from yum versionlock list.
    choices: ['absent', 'present']
    type: str
    default: present
notes:
  - Requires yum-plugin-versionlock package on the remote node.
requirements:
  - yum
  - yum-versionlock
author:
  - Florian Paul Azim Hoberg (@gyptazy)
  - Amin Vakil (@aminvakil)
a[  
- name: Prevent Apache / httpd from being updated
  community.general.yum_versionlock:
    state: present
    name:
      - httpd

- name: Prevent Apache / httpd version 2.4.57-2 from being updated
  community.general.yum_versionlock:
    state: present
    name:
      - httpd-0:2.4.57-2.el9

- name: Prevent multiple packages from being updated
  community.general.yum_versionlock:
    state: present
    name:
      - httpd
      - nginx
      - haproxy
      - curl

- name: Remove lock from Apache / httpd to be updated again
  community.general.yum_versionlock:
    state: absent
    name: httpd
z
packages:
  description: A list of package(s) in versionlock list.
  returned: success
  type: list
  elements: str
  sample: ['httpd']
state:
  description: State of package(s).
  returned: success
  type: str
  sample: present
N)AnsibleModule)	to_native)fnmatchzZ^(?P<exclude>!)?(?P<epoch>\d+):(?P<name>.+)-(?P<version>.+)-(?P<release>.+)\.(?P<arch>.+)$zZ^(?P<exclude>!)?(?P<name>.+)-(?P<epoch>\d+):(?P<version>.+)-(?P<release>.+)\.(?P<arch>.+)$c                       e Zd Zd Zd Zd Zy)YumVersionLockc                 d    || _         |j                  | _        |j                  dd      | _        y )NyumT)required)moduleparamsget_bin_pathyum_bin)selfr   s     u/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/yum_versionlock.py__init__zYumVersionLock.__init__h   s+    mm**54*@    c                 L   | j                   j                  | j                  ddg      \  }}}|dk(  r|S |dk(  r8d|v r4| j                   j                  dt	        |      z   t	        |      z          | j                   j                  dt	        |      z   t	        |      z          y	)
z4 Get an overview of all packages on yum versionlock versionlocklistr      zo such command:z;Error: Please install rpm package yum-plugin-versionlock : msgError: Nr   run_commandr   	fail_jsonr   )r   rcouterrs       r   get_versionlock_packagesz'YumVersionLock.get_versionlock_packagesm   s    {{..mV/TUC7J1W*c1KK!!&cfopsft&t  xA  BE  xF  'F!  G)in"<y~"MNr   c                    | j                   j                  | j                  dd|g|z         \  }}}d|v r| j                   j                  |       |dk(  ry| j                   j                  dt	        |      z   t	        |      z          y)	z Ensure packages state z-qr   zNo package found forr   r   Tr   Nr   )r   packagescommandr    r!   r"   s         r   ensure_statezYumVersionLock.ensure_statev   s~    {{..dMSZ/[^f/fgC!S(KK!!c!*7)in"<y~"MNr   N)__name__
__module____qualname__r   r#   r'    r   r   r
   r
   g   s    A
OOr   r
   c                     d}t         j                  |       }|st        j                  |       }|syt        |j	                  d      |      rd}| j                  d      |k(  rd}|S )NFnameTz.*)NEVRA_RE_YUMmatchNEVRA_RE_DNFr   grouprstrip)entryr-   r/   ms       r   r/   r/      sb    E5!Au%qwwv%||DT!Lr   c            
         t        t        t        dddg      t        ddd            d	      } | j                  d
   }| j                  d   }d}t        |       }|j	                         }g }|dv rad}|D ]6  t        fd|j                         D              r&|j                         8 |r| j                  rd}nw|j                  ||      }nd|dv r`d}|D ]6  t        fd|j                         D              s&|j                         8 |r!| j                  rd}n|j                  ||      }| j                  |||d       y)z? start main program to add/delete a package to yum versionlock presentabsent)defaultchoicesTr   str)r   typeelements)stater-   )argument_specsupports_check_moder=   r-   F)r6   addc              3   6   K   | ]  }t        |        y wNr/   .0pkg
single_pkgs     r   	<genexpr>zmain.<locals>.<genexpr>   s     V#uS*-V   )r7   deletec              3   6   K   | ]  }t        |        y wrB   rC   rD   s     r   rH   zmain.<locals>.<genexpr>   s     Rc5j)RrI   )r%   r=   )changedmetaN)r   dictr   r
   r#   anysplitappend
check_moder'   	exit_json)	r   r=   r%   rL   yum_vversionlock_packagespackages_listr&   rG   s	           @r   mainrW      si   y9h2GHt&5A
 !F MM'"E}}V$HG6"E !99; M" 	1JV9M9S9S9UVV$$Z0	1   ,,]GD	,	" 	1JR5I5O5O5QRR$$Z0	1   ,,]GD
 
  r   __main__)
__future__r   r   r   r;   __metaclass__DOCUMENTATIONEXAMPLESRETURNreansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r   compiler.   r0   r
   r/   rW   r(   r+   r   r   <module>rb      s    A @$L8
 
 4 A  rzz L Mrzz < =O O40f zF r   