ローカルユーザを使用してWindowsサーバにログインし、Active Directoryユーザを使用してネットワークドライブをマップし、Ansibleで自動化されたインストーラを実行します。可能なWindows共有からインストーラを実行する
私はthis questionの提案に従って、PowerShellスクリプトを作成し、マウントとインストールを行いました。
param(
$map_user,
$map_password,
$script
)
$PWord="$map_password"|ConvertTo-SecureString -AsPlainText -Force
$myCreds=New-Object System.Management.Automation.PsCredential($map_user,$PWord)
New-PSDrive -Name "Z" -PSProvider "FileSystem" -Root "\\domain\share" -Credential $myCreds
echo Invoke-Command -ScriptBlock $script
そして、私はエラーを取得する:
在庫:
[winserver]
windows
[winserver:vars]
ansible_user="local_user"
ansible_password="[email protected]"
ansible_connection="winrm"
ansible_winrm_cert_validation=ignore
win_user="domain\aduser"
win_pass="[email protected]"
タスクYAML:
---
- name: Mount and run a script
script: 'files/maprun.ps1 -map_user {{ win_user }} -map_password {{ win_pass }} -script z:\ascript.ps1'
そしてmaprun.ps1
スクリプトは、次のものが含まれ、次のように私は、そのスクリプトを使用しました:
New-PSDrive: A specified logon session does not exist. It may already have
been terminated
ほとんどのヒットはダブルホップの問題ですが、リモートスクリプトでは異なる資格情報を指定しようとしています。したがって、これはダブルホップの問題ではありません。もう1つの答えは、これが可能であるべきだと示唆している。スクリプトはインタラクティブモードで動作するので、バッチモードであることと関係しています。どのように私はこれを動作させることができます任意のアイデア?
私はRed Hat Enterprise LinuxでAnsible 2.3.1.0を使用しています。 WindowsはWindows Server 2012 R2です。スクリプトは手作業で入力されました。
ユーザ名またはパスワードがスペースやその他を含む任意のチャンス特殊文字、および何とか引用符が必要ですか? "〜map_user"} "-map_password" {{win_pass}} "' – TessellatingHeckler
私は実際にその行全体を引用していました(それを反映するように変更しました)。パスワードを間違ったパスワードに変更すると、別のエラーが表示されるので、パスワードはOKです: 'New-PSDrive:指定されたネットワークパスワードが正しくありません。 ' –