HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/lib/python3.9/site-packages/ansible/modules/__pycache__/systemd.cpython-39.pyc
a

�)gK[�@s�ddlmZmZmZeZdZdZdZddl	Z	ddl
mZddlm
Z
ddlmZmZmZdd	lmZd
d�Zdd
�Zdd�Zdd�Zdd�Zedkr�e�dS)�)�absolute_import�division�print_functiona�
module: systemd_service
author:
    - Ansible Core Team
version_added: "2.2"
short_description:  Manage systemd units
description:
    - Controls systemd units (services, timers, and so on) on remote hosts.
options:
    name:
        description:
            - Name of the unit. This parameter takes the name of exactly one unit to work with.
            - When no extension is given, it is implied to a C(.service) as systemd.
            - When using in a chroot environment you always need to specify the name of the unit with the extension. For example, C(crond.service).
        type: str
        aliases: [ service, unit ]
    state:
        description:
            - C(started)/C(stopped) are idempotent actions that will not run commands unless necessary.
              C(restarted) will always bounce the unit. C(reloaded) will always reload.
        type: str
        choices: [ reloaded, restarted, started, stopped ]
    enabled:
        description:
            - Whether the unit should start on boot. B(At least one of state and enabled are required.)
        type: bool
    force:
        description:
            - Whether to override existing symlinks.
        type: bool
        version_added: 2.6
    masked:
        description:
            - Whether the unit should be masked or not, a masked unit is impossible to start.
        type: bool
    daemon_reload:
        description:
            - Run daemon-reload before doing any other operations, to make sure systemd has read any changes.
            - When set to C(true), runs daemon-reload even if the module does not start or stop anything.
        type: bool
        default: no
        aliases: [ daemon-reload ]
    daemon_reexec:
        description:
            - Run daemon_reexec command before doing any other operations, the systemd manager will serialize the manager state.
        type: bool
        default: no
        aliases: [ daemon-reexec ]
        version_added: "2.8"
    scope:
        description:
            - Run systemctl within a given service manager scope, either as the default system scope C(system),
              the current user's scope C(user), or the scope of all users C(global).
            - "For systemd to work with 'user', the executing user must have its own instance of dbus started and accessible (systemd requirement)."
            - "The user dbus process is normally started during normal login, but not during the run of Ansible tasks.
              Otherwise you will probably get a 'Failed to connect to bus: no such file or directory' error."
            - The user must have access, normally given via setting the C(XDG_RUNTIME_DIR) variable, see example below.

        type: str
        choices: [ system, user, global ]
        default: system
        version_added: "2.7"
    no_block:
        description:
            - Do not synchronously wait for the requested operation to finish.
              Enqueued job will continue without Ansible blocking on its completion.
        type: bool
        default: no
        version_added: "2.3"
extends_documentation_fragment: action_common_attributes
attributes:
    check_mode:
        support: full
    diff_mode:
        support: none
    platform:
        platforms: posix
notes:
    - Since 2.4, one of the following options is required C(state), C(enabled), C(masked), C(daemon_reload), (C(daemon_reexec) since 2.8),
      and all except C(daemon_reload) and (C(daemon_reexec) since 2.8) also require C(name).
    - Before 2.4 you always required C(name).
    - Globs are not supported in name, i.e C(postgres*.service).
    - The service names might vary by specific OS/distribution
requirements:
    - A system managed by systemd.
a�
- name: Make sure a service unit is running
  ansible.builtin.systemd:
    state: started
    name: httpd

- name: Stop service cron on debian, if running
  ansible.builtin.systemd:
    name: cron
    state: stopped

- name: Restart service cron on centos, in all cases, also issue daemon-reload to pick up config changes
  ansible.builtin.systemd:
    state: restarted
    daemon_reload: true
    name: crond

- name: Reload service httpd, in all cases
  ansible.builtin.systemd:
    name: httpd.service
    state: reloaded

- name: Enable service httpd and ensure it is not masked
  ansible.builtin.systemd:
    name: httpd
    enabled: true
    masked: no

- name: Enable a timer unit for dnf-automatic
  ansible.builtin.systemd:
    name: dnf-automatic.timer
    state: started
    enabled: true

- name: Just force systemd to reread configs (2.4 and above)
  ansible.builtin.systemd:
    daemon_reload: true

- name: Just force systemd to re-execute itself (2.8 and above)
  ansible.builtin.systemd:
    daemon_reexec: true

- name: Run a user service when XDG_RUNTIME_DIR is not set on remote login
  ansible.builtin.systemd:
    name: myservice
    state: started
    scope: user
  environment:
    XDG_RUNTIME_DIR: "/run/user/{{ myuid }}"
aE
status:
    description: A dictionary with the key=value pairs returned from C(systemctl show).
    returned: success
    type: complex
    sample: {
            "ActiveEnterTimestamp": "Sun 2016-05-15 18:28:49 EDT",
            "ActiveEnterTimestampMonotonic": "8135942",
            "ActiveExitTimestampMonotonic": "0",
            "ActiveState": "active",
            "After": "auditd.service systemd-user-sessions.service time-sync.target systemd-journald.socket basic.target system.slice",
            "AllowIsolate": "no",
            "Before": "shutdown.target multi-user.target",
            "BlockIOAccounting": "no",
            "BlockIOWeight": "1000",
            "CPUAccounting": "no",
            "CPUSchedulingPolicy": "0",
            "CPUSchedulingPriority": "0",
            "CPUSchedulingResetOnFork": "no",
            "CPUShares": "1024",
            "CanIsolate": "no",
            "CanReload": "yes",
            "CanStart": "yes",
            "CanStop": "yes",
            "CapabilityBoundingSet": "18446744073709551615",
            "ConditionResult": "yes",
            "ConditionTimestamp": "Sun 2016-05-15 18:28:49 EDT",
            "ConditionTimestampMonotonic": "7902742",
            "Conflicts": "shutdown.target",
            "ControlGroup": "/system.slice/crond.service",
            "ControlPID": "0",
            "DefaultDependencies": "yes",
            "Delegate": "no",
            "Description": "Command Scheduler",
            "DevicePolicy": "auto",
            "EnvironmentFile": "/etc/sysconfig/crond (ignore_errors=no)",
            "ExecMainCode": "0",
            "ExecMainExitTimestampMonotonic": "0",
            "ExecMainPID": "595",
            "ExecMainStartTimestamp": "Sun 2016-05-15 18:28:49 EDT",
            "ExecMainStartTimestampMonotonic": "8134990",
            "ExecMainStatus": "0",
            "ExecReload": "{ path=/bin/kill ; argv[]=/bin/kill -HUP $MAINPID ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
            "ExecStart": "{ path=/usr/sbin/crond ; argv[]=/usr/sbin/crond -n $CRONDARGS ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
            "FragmentPath": "/usr/lib/systemd/system/crond.service",
            "GuessMainPID": "yes",
            "IOScheduling": "0",
            "Id": "crond.service",
            "IgnoreOnIsolate": "no",
            "IgnoreOnSnapshot": "no",
            "IgnoreSIGPIPE": "yes",
            "InactiveEnterTimestampMonotonic": "0",
            "InactiveExitTimestamp": "Sun 2016-05-15 18:28:49 EDT",
            "InactiveExitTimestampMonotonic": "8135942",
            "JobTimeoutUSec": "0",
            "KillMode": "process",
            "KillSignal": "15",
            "LimitAS": "18446744073709551615",
            "LimitCORE": "18446744073709551615",
            "LimitCPU": "18446744073709551615",
            "LimitDATA": "18446744073709551615",
            "LimitFSIZE": "18446744073709551615",
            "LimitLOCKS": "18446744073709551615",
            "LimitMEMLOCK": "65536",
            "LimitMSGQUEUE": "819200",
            "LimitNICE": "0",
            "LimitNOFILE": "4096",
            "LimitNPROC": "3902",
            "LimitRSS": "18446744073709551615",
            "LimitRTPRIO": "0",
            "LimitRTTIME": "18446744073709551615",
            "LimitSIGPENDING": "3902",
            "LimitSTACK": "18446744073709551615",
            "LoadState": "loaded",
            "MainPID": "595",
            "MemoryAccounting": "no",
            "MemoryLimit": "18446744073709551615",
            "MountFlags": "0",
            "Names": "crond.service",
            "NeedDaemonReload": "no",
            "Nice": "0",
            "NoNewPrivileges": "no",
            "NonBlocking": "no",
            "NotifyAccess": "none",
            "OOMScoreAdjust": "0",
            "OnFailureIsolate": "no",
            "PermissionsStartOnly": "no",
            "PrivateNetwork": "no",
            "PrivateTmp": "no",
            "RefuseManualStart": "no",
            "RefuseManualStop": "no",
            "RemainAfterExit": "no",
            "Requires": "basic.target",
            "Restart": "no",
            "RestartUSec": "100ms",
            "Result": "success",
            "RootDirectoryStartOnly": "no",
            "SameProcessGroup": "no",
            "SecureBits": "0",
            "SendSIGHUP": "no",
            "SendSIGKILL": "yes",
            "Slice": "system.slice",
            "StandardError": "inherit",
            "StandardInput": "null",
            "StandardOutput": "journal",
            "StartLimitAction": "none",
            "StartLimitBurst": "5",
            "StartLimitInterval": "10000000",
            "StatusErrno": "0",
            "StopWhenUnneeded": "no",
            "SubState": "running",
            "SyslogLevelPrefix": "yes",
            "SyslogPriority": "30",
            "TTYReset": "no",
            "TTYVHangup": "no",
            "TTYVTDisallocate": "no",
            "TimeoutStartUSec": "1min 30s",
            "TimeoutStopUSec": "1min 30s",
            "TimerSlackNSec": "50000",
            "Transient": "no",
            "Type": "simple",
            "UMask": "0022",
            "UnitFileState": "enabled",
            "WantedBy": "multi-user.target",
            "Wants": "system.slice",
            "WatchdogTimestampMonotonic": "0",
            "WatchdogUSec": "0",
        }
N)�
AnsibleModule)�	is_chroot)�sysv_exists�sysv_is_enabled�fail_if_missing)�	to_nativecCs|dtddg�vS)N�ActiveStateZactiveZ
activating��set�Zservice_status�r�;/usr/lib/python3.9/site-packages/ansible/modules/systemd.py�is_running_servicesrcCs|dtdg�vS)NrZdeactivatingrrrrr�is_deactivating_service"srcCsd|vod|vpd|vS)N�=zignoring requestzignoring commandr)�outrrr�request_was_ignored&srcCs�i}g}d}|D]�}|durxd|vr�|�dd�\}}|�d�rf|���d�rf|���d�sf|�|�q|��||<d}q|�|�|���d�rd�|���||<g}d}q|S)Nr�ZExec�{�}�
)�split�
startswith�lstrip�rstrip�endswith�append�strip�join)�lines�parsedZmultival�k�line�vrrr�parse_systemctl_show*s&


r'cCs$tttdddgd�tdgd�d�tdd�tdd�tdd�tdd	d
gd�tdd	dgd�tdd
gd�d�tdd	d�d�	dgd�gtdddd�d�}|jd}|dur�dD] }||vr�|jd||fd�q�|�dd�}t�d�dur�dt��tjd<|jdd
k�r|d|jd7}|jd �r(|d!7}|jd"�r<|d#7}d$}d%}}t|d	t�d&�}|jd'�r�|j	�s�|�
d(|�\}}}|d$k�r�|jd)||fd�|jd*�r�|j	�s�|�
d+|�\}}}|d$k�r�|jd,||fd�|�rd	}t|�}	d	}
|�
d-||f�\}}}|d$k�r�t|��s�t|��s�|�r�t
t|��d.��|d/<d0|d/v�oh|d/d0d1k}
d0|d/v�o�|d/d0d2k}|
�r�|�s�d3|d/v�r�|jd4||d/d3fd��n|�r`|d5k�r`d6|v�r`t
t|��d.��|d/<|�d7�\}}
}d8j||
d9�}|�
d:j||d;��\}}}||v}
|�
d<j||d=��\}}}|�d.�|d/d><njgd?�}|�
d@||f�\}}}|��|v�r�d}
n6|�
dA||f�\}}}|d$k�r�d}
n|j
|ddB�|
�p�|	}|	�r�|
�s�|�dC|�|jd2du�r�|�
d@||f�\}}}|��d2k}||jd2k�r�d|dD<|jd2�rLdE}ndF}|j	�s�|�
dG|||f�\}}}|d$k�r�t|||dHd�|jdIdu�r�|jdI�r�dJ}ndK}t|||dHd�d	}|�
dL||f�\}}}|d$k�rd}|��dMgk�s|��dNgk�rPd	}n>|d5k�rP|jdd
k�rP|	�rP|���dO��sPt|��rPd}||dI<||jdIk�r�d|dD<|j	�s�|�
dG|||f�\}}}|d$k�r�|jdP||||fd�||dI<|jdQdu�rt|||dHd�|jdQ|dQ<d>|d/v�r�d}|jdQdRk�r$t|d/��s�dS}n`|jdQdTk�rVt|d/��sPt|d/��r�dU}n.t|d/��sjdS}n|jdQddV�}dR|dQ<|�rd|dD<|j	�s|�
dG|||f�\}}}|d$k�r|jdP|||fd�n:t|��s�tj�dW�dXk�r�|�dY�n|jdZ|d/d[�|jfi|��dS)\N�strZservice�unit)�type�aliases)ZreloadedZ	restarted�started�stopped)r*�choices�bool)r*Fz
daemon-reload)r*�defaultr+z
daemon-reexec�system)r1�user�global)r*r0r.)r*r0)	�name�state�enabled�force�masked�
daemon_reload�
daemon_reexec�scope�no_blockT)r5r6r8r9r:)r4)r5r6r8)Z
argument_specZsupports_check_modeZrequired_one_ofZrequired_byr4)�*�?�[zZThis module does not currently support using glob patterns, found '%s' in service name: %s)�msg�	systemctlZXDG_RUNTIME_DIRz/run/user/%sr;z --%sr<z --no-blockr7z --forcer�)r4�changed�statusr9z%s daemon-reloadz#failure %d during daemon-reload: %sr:z%s daemon-reexecz#failure %d during daemon-reexec: %sz%s show '%s'rrDZ	LoadStatez	not-foundr8Z	LoadErrorz Error loading unit file '%s': %srzFailed to parse bus message�@z{unit_base}{sep})�	unit_base�sepz,{systemctl} list-unit-files '{unit_search}*')rA�unit_searchz{systemctl} is-active '{unit}')rAr)r)r6zenabled-runtimeZlinkedzlinked-runtimer8zmasked-runtimeZstatic�indirect�disabledZ	generatedZ	transientz%s is-enabled '%s'z%s list-unit-files '%s')Zcheck_rczPThe service (%s) is actually an init script but the system is managed by systemdrC�maskZunmaskz
%s %s '%s'�hostr6�enable�disablez%s is-enabled '%s' -lrI�aliasrJzUnable to %s service %s: %sr5r,�startr-�stop���ZSYSTEMD_OFFLINE�1zyTarget is a chroot or systemd is offline. This can lead to false positives or prevent the init system tools from working.zService is in unknown state)r@rD)r�dict�paramsZ	fail_jsonZget_bin_path�os�getenv�geteuid�environZ
check_modeZrun_commandrrr'r
r�	partition�formatrr �warnr	�
splitlinesrrrrr�getZ	exit_json)�moduler)ZglobpatternrA�rcr�err�result�foundZis_initdZ
is_systemdZ	is_maskedrFrG�suffixrHZvalid_enabled_statesr8�actionr6rrr�mainPs"
���
�

 




 
���


rf�__main__)Z
__future__rrrr*Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrVZansible.module_utils.basicrZ(ansible.module_utils.facts.system.chrootrZansible.module_utils.servicerrr	Zansible.module_utils._textr
rrrr'rf�__name__rrrr�<module>s$W3&i