使用Ansible自动配置Octopus触手

时间:2016-03-23 11:15:59

标签: powershell ansible ansible-playbook octopus-deploy

我有一个运行PowerShell脚本的剧本来配置Octopus Deploy触手。

如果我在服务器上运行此PowerShell脚本,它可以完美运行。如果我使用PowerShell脚本运行playbook,它将在服务器上失败。

可能导致这种情况的原因是什么?权限?计时?

Playbook:
---
- name: Configure Octopus Deploy Tentecle
  hosts: all
  tasks:
    - name: Configure Octopus Deploy Tentecle
      script: files/octo_autoconfig.ps1

PowerShell脚本:

& "C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe" create-instance --instance "Tentacle" --config "C:\Octopus\Tentacle.config" --console;
& "C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe" new-certificate --instance "Tentacle" --if-blank --console;
& "C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe" configure --instance "Tentacle" --reset-trust --console;
& "C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe" configure --instance "Tentacle" --home "C:\Octopus" --app "C:\Octopus\Applications" --port "10933" --noListen "False" --console;
& "C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe" configure --instance "Tentacle" --trust "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" --console;
& "C:\Program Files\Octopus Deploy\Tentacle\Tentacle.exe" service --instance "Tentacle" --install --start --console;

在运行playbook配置Octopus后尝试打开Octopus Tentacle时出现错误:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Octopus.Tools.TentacleConfiguration.TentacleManager.TentacleManagerModel.Reload(ApplicationInstanceRecord applicationInstance) in y:\work\refs\heads\master\source\Octopus.Tools\TentacleConfiguration\TentacleManager\TentacleManagerModel.cs:line 131
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

请注意,如果我直接在服务器上运行PowerShell脚本,它可以完美地运行并配置触手。如果我然后移除触手然后运行playbook它工作。因此,在Ansible playbook可以工作之前,就好像需要先在服务器上直接配置触手。哪种方式失败了。

我查看了服务器的事件查看器,并且有一些拒绝访问错误,如下所示。

有没有办法让特定管理员用户运行此脚本,以便没有拒绝访问权限?

2016-02-24 15:53:12.2675      1 FATAL  System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at Octopus.Shared.Internals.CertificateGeneration.Win32ErrorHelper.ThrowExceptionIfGetLastErrorIsNotZero() in y:\work\refs\heads\master\source\Octopus.Shared\Internals\CertificateGeneration\Win32ErrorHelper.cs:line 13
   at Octopus.Shared.Internals.CertificateGeneration.CryptContext.Open() in y:\work\refs\heads\master\source\Octopus.Shared\Internals\CertificateGeneration\CryptContext.cs:line 38
   at Octopus.Shared.Security.CertificateGenerator.Generate(String fullName, Boolean exportable) in y:\work\refs\heads\master\source\Octopus.Shared\Security\CertificateGenerator.cs:line 27
   at Octopus.Shared.Configuration.TentacleConfiguration.GenerateNewCertificate() in y:\work\refs\heads\master\source\Octopus.Shared\Configuration\TentacleConfiguration.cs:line 188
   at Octopus.Tentacle.Commands.NewCertificateCommand.Start() in y:\work\refs\heads\master\source\Octopus.Tentacle\Commands\NewCertificateCommand.cs:line 58
   at Octopus.Shared.Startup.AbstractCommand.Octopus.Shared.Startup.ICommand.Start(String[] commandLineArguments, ICommandRuntime commandRuntime, OptionSet commonOptions) in y:\work\refs\heads\master\source\Octopus.Shared\Startup\AbstractCommand.cs:line 58
   at Octopus.Shared.Startup.ConsoleHost.Run(Action`1 start, Action shutdown) in y:\work\refs\heads\master\source\Octopus.Shared\Startup\ConsoleHost.cs:line 36

1 个答案:

答案 0 :(得分:0)

我认为你在新证书步骤中遇到了这个错误。

http://docs.octopusdeploy.com/display/OD2/Export+and+import+Tentacle+certificates+without+a+profile

您需要生成证书并将其上传到目标,以便使用触手进行导入。