在脱机环境中运行Ansible 2.4.2,使用kerberos进行身份验证,
通过ansible playbook,使用特定(域)用户运行PowerShell脚本的正确语法是什么:DOMAIN \ someuser,处于提升模式?
通过提升模式,我的意思是在Windows界面中,我通过以DOMAIN \ someuser身份登录来运行脚本,然后通过右键单击cmd或powershell提示快捷方式,选择“以管理员身份运行”。 这当然并不意味着我可以与本地用户一起运行脚本:“administrator”。
我想要运行的是:
powershell.exe -executionpolicy bypass -noninteractive -nologo -file "myscript.ps1"
我在一个过去的尝试:
- 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
脚本运行,其中的错误与未在高程中运行有关。 尝试使用win_shell和raw。尝试没有become_user和become_password(yml使用someuser@DOMAIN.local用户和密码运行,所以我真的不知道是否需要它)。
我正在拖拽这个并且没有通过以下方式找到解决方案: http://docs.ansible.com/ansible/latest/become.html
有什么想法吗?
答案 0 :(得分:2)
我之前使用过PsExec作为特定Windows域用户运行任务,需要加载配置文件的软件安装。您还可以使用它来模拟远程系统上的提升用户来运行PowerShell脚本。
这不是我的第一选择,但我也遇到了在Windows主机上工作的问题。
- name: Copy PsExec
win_copy:
src: "files/PsExec.exe"
dest: "c:\\temp\\psexec.exe"
force: no
- name: Run powershell as a specific domain user
win_psexec:
command: "powershell.exe -executionpolicy bypass -noninteractive -nologo -file 'myscript.ps1'"
executable: C:\temp\psexec.exe
elevated: yes
nobanner: yes
username: "{{ dom_username }}"
password: "{{ dev_password }}"
interactive: yes
答案 1 :(得分:2)
我做了以下操作,以便在我的剧本中使用它:
- 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