Source code for saltext.apache.modules.suse_apache
"""Support for ApachePlease note: The functions in here are SUSE-specific. Placing them in thisseparate file will allow them to load only on SUSE systems, while stillloading under the ``apache`` namespace."""importloggingimportsalt.utils.pathlog=logging.getLogger(__name__)__virtualname__="apache"
[docs]def__virtual__():""" Only load the module if apache is installed. """ifsalt.utils.path.which("apache2ctl")and__grains__["os_family"]=="Suse":return__virtualname__return(False,"apache execution module not loaded: apache not installed.")
[docs]defcheck_mod_enabled(mod):""" Checks to see if the specific apache mod is enabled. This will only be functional on operating systems that support `a2enmod -l` to list the enabled mods. CLI Example: .. code-block:: bash salt '*' apache.check_mod_enabled status """ifmod.endswith(".load")ormod.endswith(".conf"):mod_name=mod[:-5]else:mod_name=modcmd="a2enmod -l"try:active_mods=__salt__["cmd.run"](cmd,python_shell=False).split(" ")exceptExceptionase:# pylint: disable=broad-exceptreturnereturnmod_nameinactive_mods
[docs]defa2enmod(mod):""" Runs a2enmod for the given mod. CLI Example: .. code-block:: bash salt '*' apache.a2enmod vhost_alias """ret={}command=["a2enmod",mod]try:status=__salt__["cmd.retcode"](command,python_shell=False)exceptExceptionase:# pylint: disable=broad-exceptreturneret["Name"]="Apache2 Enable Mod"ret["Mod"]=modifstatus==1:ret["Status"]=f"Mod {mod} Not found"elifstatus==0:ret["Status"]=f"Mod {mod} enabled"else:ret["Status"]=statusreturnret
[docs]defa2dismod(mod):""" Runs a2dismod for the given mod. CLI Example: .. code-block:: bash salt '*' apache.a2dismod vhost_alias """ret={}command=["a2dismod",mod]try:status=__salt__["cmd.retcode"](command,python_shell=False)exceptExceptionase:# pylint: disable=broad-exceptreturneret["Name"]="Apache2 Disable Mod"ret["Mod"]=modifstatus==256:ret["Status"]=f"Mod {mod} Not found"elifstatus==0:ret["Status"]=f"Mod {mod} disabled"else:ret["Status"]=statusreturnret