
    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  e	j                  d      Zd Zd	 Zd
 Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: apache2_module
author:
  - Christian Berendt (@berendt)
  - Ralf Hertel (@n0trax)
  - Robin Roth (@robinro)
short_description: Enables/disables a module of the Apache2 webserver
description:
  - Enables or disables a specified module of the Apache2 webserver.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  name:
    type: str
    description:
      - Name of the module to enable/disable as given to C(a2enmod)/C(a2dismod).
    required: true
  identifier:
    type: str
    description:
      - Identifier of the module as listed by C(apache2ctl -M). This is optional and usually determined automatically by the
        common convention of appending V(_module) to O(name) as well as custom exception for popular modules.
    required: false
  force:
    description:
      - Force disabling of default modules and override Debian warnings.
    required: false
    type: bool
    default: false
  state:
    type: str
    description:
      - Desired state of the module.
    choices: ['present', 'absent']
    default: present
  ignore_configcheck:
    description:
      - Ignore configuration checks about inconsistent module configuration. Especially for mpm_* modules.
    type: bool
    default: false
  warn_mpm_absent:
    description:
      - Control the behavior of the warning process for MPM modules.
    type: bool
    default: true
    version_added: 6.3.0
requirements: ["a2enmod", "a2dismod"]
notes:
  - This does not work on RedHat-based distributions. It does work on Debian- and SuSE-based distributions. Whether it works
    on others depend on whether the C(a2enmod) and C(a2dismod) tools are available or not.
a&  
- name: Enable the Apache2 module wsgi
  community.general.apache2_module:
    state: present
    name: wsgi

- name: Disables the Apache2 module wsgi
  community.general.apache2_module:
    state: absent
    name: wsgi

- name: Disable default modules for Debian
  community.general.apache2_module:
    state: absent
    name: autoindex
    force: true

- name: Disable mpm_worker and ignore warnings about missing mpm module
  community.general.apache2_module:
    state: absent
    name: mpm_worker
    ignore_configcheck: true

- name: Disable mpm_event, enable mpm_prefork and ignore warnings about missing mpm module
  community.general.apache2_module:
    name: "{{ item.module }}"
    state: "{{ item.state }}"
    warn_mpm_absent: false
    ignore_configcheck: true
  loop:
    - module: mpm_event
      state: absent
    - module: mpm_prefork
      state: present

- name: Enable dump_io module, which is identified as dumpio_module inside apache2
  community.general.apache2_module:
    state: present
    name: dump_io
    identifier: dumpio_module
a  
result:
  description: Message about action taken.
  returned: always
  type: str
warnings:
  description: List of warning messages.
  returned: when needed
  type: list
rc:
  description: Return code of underlying command.
  returned: failed
  type: int
stdout:
  description: The stdout of underlying command.
  returned: failed
  type: str
stderr:
  description: The stderr of underlying command.
  returned: failed
  type: str
N)AnsibleModulezthreaded: *yesc                     t        |       }| j                  |dg      \  }}}t        t        j	                  |            S )Nz-V)_get_ctl_binaryrun_commandbool_re_threadedsearch)modulecontrol_binaryresultstdoutstderrs        t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/apache2_module.py_run_threadedr      s>    $V,N#//0FGFFF##F+,,    c                 d    dD ]  }| j                  |      }||c S  | j                  d       y )N)
apache2ctl	apachectlz[Neither of apache2ctl nor apachectl found. At least one apache control binary is necessary.msg)get_bin_path	fail_json)r   command
ctl_binarys      r   r   r      sA    . ((1
!
 vwr   c                    t        |       }| j                  |dg      \  }}}|dk7  rd|d|}| j                  d   r\d|v r<d| j                  d   v r+| j                  d	   r| j                  j	                  d
       y| j                  j	                  |       y| j                  |       d| j                  d   z   }||v S )Nz-Mr   zError executing z: ignore_configcheckAH00534mpm_namewarn_mpm_absentzoNo MPM module loaded! apache2 reload AND other module actions will fail if no MPM module is loaded immediately.Fr    
identifier)r   r	   paramswarningsappendr   )r   r   r   r   r   	error_msgsearchstrings          r   _module_is_enabledr+      s    $V,N#//0FGFFF{0>G	==-.F"vv1F'F==!23OO**M  &&y1+|44L6!!r   c                    g d}dt        j                  d      fdt        j                  d      fg}|D ]  \  }}|| v s|c S  |D ]1  \  }}|| v s	 |j                  |       }|j                  d      dz   c S  | dz   S # t        $ r Y Dw xY w)z
    By convention if a module is loaded via name, it appears in apache2ctl -M as
    name_module.

    Some modules don't follow this convention and we use replacements for those.))shibmod_shib)shib2r.   )evasiveevasive20_modulephp8z^(php)[\d\.]+phpz
^(php\d)\.   _module)recompiler   groupAttributeError)r"   text_workaroundsre_workaroundsa2enmod_spellingmodule_namer   reexprrematchs           r   create_apache_identifierr@      s     
,-.	

=)*N
 *: %+t# ) T> ---}}Q')33	 ) " s   $B  	BBc                    | j                   d   }| j                   d   }|dk(  }ddd|   }ddd|   }d	|d
|}t        |       |k7  r| j                  r| j                  d|| j                         | j                  |      }|| j                  |d|d       |g}	|s|r|	j                  d       | j                  |	|gz         \  }
}}t        |       |k(  r| j                  d|| j                         y dj                  |||| j                   d         }| j                  ||
||       y | j                  d|| j                         y )Nr"   forcepresentenableddisabledrC   absenta2enmoda2dismodzModule r$   T)changedr   r'   z- not found. Perhaps this system does not use z to manage apacher   z-fzFailed to set module {name} to {state}:
{stdout}
Maybe the module identifier ({identifier}) was guessed incorrectly.Consider setting the "identifier" option.r%   )r"   stater   r%   )r   rcr   r   F)
r&   r+   
check_mode	exit_jsonr'   r   r   r(   r	   format)r   rK   r"   rB   want_enabledstate_stringa2mod_binarysuccess_msga2mod_binary_patha2mod_binary_cmdr   r   r   r   s                 r   
_set_staterV      s   == DMM'"EI%L(J?FL(J?FL$(,7K&!\1T$/&,oo  7 #//=$iu  xD  "E  F-.##D)!'!3!34Dv4M!Nf%5T$/&,oo  7
< f"!==6	     &$*$*  ,
 	 +"(// 	 	3r   c                     t        t        t        d      t        d      t        dd      t        dd	dg
      t        dd      t        dd            d      } g | _        | j                  d   }|dk(  rt	        |       r| j                  d       | j                  d   s%t        | j                  d         | j                  d<   | j                  d   dv rt        | | j                  d          y y )NT)requiredstr)typer
   F)rZ   defaultrC   rG   )r[   choices)r"   r%   rB   rK   r   r#   )argument_specsupports_check_moder"   cgizKYour MPM seems to be threaded. No automatic actions on module cgi possible.r   r%   rK   rF   )r   dictr'   r&   r   r   r@   rV   )r   r"   s     r   mainra     s    t$'FE2y8Y2GH#? fd;
 !
F FO== Du}v.jk==&&>v}}V?T&Ul#}}W!6666==12 7r   __main__)
__future__r   r   r   rZ   __metaclass__DOCUMENTATIONEXAMPLESRETURNr6   ansible.module_utils.basicr   r7   r   r   r   r+   r@   rV   ra   __name__ r   r   <module>rk      sz    A @7r(T
. 
 5rzz+,-x". F23j34 zF r   