
    Vh:                    n    d dl mZ dZdZd dlmZ d dlmZ d dl	m
Z
  e e
d            Z G d d	e      Zy
)    )annotationsa  
name: machinectl
short_description: Systemd's machinectl privilege escalation
description:
  - This become plugins allows your remote/login user to execute commands as another user using the C(machinectl) utility.
author: Ansible Core Team
options:
  become_user:
    description: User you 'become' to execute the task.
    type: string
    default: ''
    ini:
      - section: privilege_escalation
        key: become_user
      - section: machinectl_become_plugin
        key: user
    vars:
      - name: ansible_become_user
      - name: ansible_machinectl_user
    env:
      - name: ANSIBLE_BECOME_USER
      - name: ANSIBLE_MACHINECTL_USER
  become_exe:
    description: C(machinectl) executable.
    type: string
    default: machinectl
    ini:
      - section: privilege_escalation
        key: become_exe
      - section: machinectl_become_plugin
        key: executable
    vars:
      - name: ansible_become_exe
      - name: ansible_machinectl_exe
    env:
      - name: ANSIBLE_BECOME_EXE
      - name: ANSIBLE_MACHINECTL_EXE
  become_flags:
    description: Options to pass to C(machinectl).
    type: string
    default: ''
    ini:
      - section: privilege_escalation
        key: become_flags
      - section: machinectl_become_plugin
        key: flags
    vars:
      - name: ansible_become_flags
      - name: ansible_machinectl_flags
    env:
      - name: ANSIBLE_BECOME_FLAGS
      - name: ANSIBLE_MACHINECTL_FLAGS
  become_pass:
    description: Password for C(machinectl).
    type: string
    required: false
    vars:
      - name: ansible_become_password
      - name: ansible_become_pass
      - name: ansible_machinectl_pass
    env:
      - name: ANSIBLE_BECOME_PASS
      - name: ANSIBLE_MACHINECTL_PASS
    ini:
      - section: machinectl_become_plugin
        key: password
notes:
  - When not using this plugin with user V(root), it only works correctly with a polkit rule which will alter the behaviour
    of machinectl. This rule must alter the prompt behaviour to ask directly for the user credentials, if the user is allowed
    to perform the action (take a look at the examples section). If such a rule is not present the plugin only work if it
    is used in context with the root user, because then no further prompt will be shown by machinectl.
ai  
# A polkit rule needed to use the module with a non-root user.
# See the Notes section for details.
/etc/polkit-1/rules.d/60-machinectl-fast-user-auth.rules: |-
  polkit.addRule(function(action, subject) {
    if(action.id == "org.freedesktop.machine1.host-shell" &&
      subject.isInGroup("wheel")) {
        return polkit.Result.AUTH_SELF_KEEP;
    }
  });
)compile)
BecomeBase)to_bytesz\x1B\[[0-9;]+mc                  `     e Zd ZdZdZdZdZdZed        Z	 fdZ
 fdZ fd	Z fd
Z xZS )BecomeModulezcommunity.general.machinectlz
Password: )z==== AUTHENTICATION FAILED ====)z!==== AUTHENTICATION COMPLETE ====Tc                .    t         j                  d|       S )N    )ansi_color_codessub)lines    o/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/become/machinectl.pyremove_ansi_codeszBecomeModule.remove_ansi_codesn   s    ##C..r
   c           
         t         t        |   ||       |s|S | j                  d      }| j                  d      }| j                  d      }| d| d| d| j	                  ||       S )N
become_exebecome_flagsbecome_userz
 -q shell  z@ )superr   build_become_command
get_option_build_success_command)selfcmdshellbecomeflagsuser	__class__s         r   r   z!BecomeModule.build_become_commandr   ss    lD6sEBJ./}-E7!D6D4O4OPSUZ4[3\]]r
   c                D    | j                  |      }t        | 	  |      S N)r   r   check_successr   b_outputr   s     r   r"   zBecomeModule.check_success~   s#    ))(3w$X..r
   c                D    | j                  |      }t        | 	  |      S r!   )r   r   check_incorrect_passwordr#   s     r   r&   z%BecomeModule.check_incorrect_password   s#    ))(3w/99r
   c                D    | j                  |      }t        | 	  |      S r!   )r   r   check_missing_passwordr#   s     r   r(   z#BecomeModule.check_missing_password   s#    ))(3w-h77r
   )__name__
__module____qualname__namepromptfailsuccessrequire_ttystaticmethodr   r   r"   r&   r(   __classcell__)r   s   @r   r   r   e   sH    )DF/D4GK/ /
^/:8 8r
   r   N)
__future__r   DOCUMENTATIONEXAMPLESrer   
re_compileansible.plugins.becomer   ansible.module_utils._textr   r   r    r
   r   <module>r;      sD   
 #GR
 % - / h'89: #8: #8r
   