Ansible playbook,在提升模式下使用特定(域)用户运行 powershell 脚本的正确语法是什么?

Nah*_*paz 6 windows powershell ansible kerberos-delegation ansible-2.x

在离线环境中运行 Ansible 2.4.2,使用 kerberos 进行身份验证,

通过 ansible playbook,在提升模式下使用特定(域)用户运行 powershell 脚本的正确语法是什么:DOMAIN\someuser?

通过提升模式,我的意思是在 Windows 界面中,我会通过以 DOMAIN\someuser 身份登录来运行脚本,然后通过右键单击 cmd 或 powershell 提示快捷方式,选择“以管理员身份运行”。这当然并不意味着我可以使用本地用户“管理员”运行脚本。

我想运行的是:

powershell.exe -executionpolicy bypass -noninteractive -nologo -file "myscript.ps1" 
Run Code Online (Sandbox Code Playgroud)

我在 become.yml 中尝试了什么:

- name: sigh
  win_command: powershell.exe -executionpolicy bypass -noninteractive -nologo -file "myscript.ps1" 
  become: yes
  become_user: DOMAIN\someuser
  become_password: someuserpassword
  become_method: runas
Run Code Online (Sandbox Code Playgroud)

脚本运行时出现与它未在高程中运行相关的错误。对 win_shell 和 raw 进行了同样的尝试。尝试不使用 become_user 和 become_password (yml 使用 someuser@DOMAIN.local 用户和密码运行,所以我真的不知道是否需要它)。

我正在拖延,并没有找到通过成为解决方案的参考:http : //docs.ansible.com/ansible/latest/become.html

有任何想法吗?

Chr*_*a A 9

我做了以下工作来让它在我的剧本中工作:

- name: Run ps1 script in privileged mode
  hosts: "{{ my_hosts }}"
  become_method: runas

  vars:
    ansible_become_password: mysupersecretpasswrod

  tasks:
    - win_shell: '.\myscript.ps1'
      become: yes
      become_user: Administrator
Run Code Online (Sandbox Code Playgroud)