Ansible with Windows Server 2012 and SQL Server 2014

1

I actually posted this question on superUser but I think it might be in the wrong place. My apologies.

I've been playing around with ansible and with WinRM to manage windows servers and have been slightly successful with it to run basic commands.

However when i try to run an exe file from within the powershell script, it fails.

The same powershell script when i run from windows directly, it runs perfectly without any errors. The only error it throws out is an Access Denied error which would link to permissions, however being the Administrator, it should have full permissions no?

The powershell script i try to run is:

Write-Host "Installing SQL Server"
C:\software-downloads\SQL\setup.exe /ConfigurationFile=C:\software-downloads\ConfigurationFile.ini

The error Ansible throws out is:

The following error occurred:
There was an error generating the XML document.
Error result: -2068774911
Result facility code: 1201
Result error code: 1
Please review the summary.txt log for further details

And looking at the summary log file it shows:

Overall summary:
  Final result:                  Failed: see details below
  Exit code (Decimal):           -2068774911
  Exit facility code:            1201
  Exit error code:               1
  Exit message:                  There was an error generating the XML document.
  Start time:                    2016-06-24 06:47:55
  End time:                      2016-06-24 06:48:15
  Requested action:              Install
  Exception help link:           http://go.microsoft.com/fwlink?LinkId=20476&ProdName=Microsoft+SQL+Server&EvtSrc=setup.rll&EvtID=50000&ProdVer=12.0.4100.1&EvtType=0xE0C083E6%400xF80B8030&EvtType=0xE0C083E6%400xF80B8030


Exception summary:
The following is an exception stack listing the exceptions in outermost to innermost order
Inner exceptions are being indented

Exception type: Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException
    Message: 
        There was an error generating the XML document.
    HResult : 0x84b10001
        FacilityCode : 1201 (4b1)
        ErrorCode : 1 (0001)
    Data: 
      DisableWatson = true
    Stack: 
        at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(String rootPath, Object objectToSerialize, Boolean saveToCache)
        at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(Object objectToSerialize)
        at Microsoft.SqlServer.Chainer.Infrastructure.InputSettingService.CalculateSettings(IEnumerable`1 settingIds)
        at Microsoft.SqlServer.Chainer.Infrastructure.InputSettingService.CalculateAllSettings(Boolean chainerSettingOnly)
        at Microsoft.SqlServer.Configuration.SetupExtension.FinalCalculateSettingsAction.ExecuteAction(String actionId)
        at Microsoft.SqlServer.Chainer.Infrastructure.Action.Execute(String actionId, TextWriter errorStream)
        at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.<>c__DisplayClasse.<ExecuteActionWithRetryHelper>b__b()
        at Microsoft.SqlServer.Setup.Chainer.Workflow.ActionInvocation.ExecuteActionHelper(ActionWorker workerDelegate)
    Inner exception type: System.InvalidOperationException
        Message: 
                There was an error generating the XML document.
        HResult : 0x80131509
        Stack: 
                at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
                at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
                at Microsoft.SqlServer.Chainer.Infrastructure.DataStoreService.SerializeObject(String rootPath, Object objectToSerialize, Boolean saveToCache)
        Inner exception type: System.Security.Cryptography.CryptographicException
            Message: 
                        Access is denied.

            HResult : 0x80070005
            Stack: 
                        at System.Security.Cryptography.ProtectedData.Protect(Byte[] userData, Byte[] optionalEntropy, DataProtectionScope scope)
                        at Microsoft.SqlServer.Common.SqlSecureString.WriteXml(XmlWriter writer)
                        at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAgentConfigurationPublic.Write6_AgentConfigurationPublic(String n, String ns, AgentConfigurationPublic o, Boolean isNullable, Boolean needType)
                        at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterAgentConfigurationPublic.Write7_AgentConfigurationPublic(Object o)

The exception help link doesn't go anywhere either when I click on it.

I tried passing the credentials as well with Start-Process but that doesn't work either as I'm probably using it wrong since i have to pass the configuration file in as a parameter.

I've run the following ansible script on the Windows Host: https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1

And I know it's working fine as I can run other scripts which include, downloading files from S3 and auto-joining to a domain.

Has anyone successfully installed an exe file in windows via ansible? Any help will awesome, as maybe I might even have over-looked something simple?

windows
powershell
ansible
windows-server-2012-r2
asked on Stack Overflow Jun 24, 2016 by Nikhil C. • edited Jun 24, 2016 by FredMaggiowski

5 Answers

1

I find a "dirty" way for install Mssql with Ansible with local system account, but it's work. With nssm, install a bat which run the mssql installer has a service, like this:

.bat:

C:\mssql_install\setup.exe /SAPWD="??????" /ConfigurationFile="c:\mssql_install\setupauto.ini" /IAcceptSQLServerLicenseTerms /INDICATEPROGRESS=False /Q

C:\nssm.exe remove myservice confirm

net stop myservice

with ansible:

  • name: install service

    raw: C:\nssm.exe install myservice C:\mssql_install\mycmd.bat

  • name: configure service

    raw: C:\nssm.exe set myservice start SERVICE_DEMAND_START

  • name: start

    raw: net start myservice

I also try with psexe -s (-s for system account) without success

answered on Stack Overflow Sep 23, 2016 by Stéphane Travassac • edited Sep 28, 2016 by Stéphane Travassac
0

I also have the same problem. I tried including the registry setting mentioned in the following article in my playbook but to no success. Can you give this a try and let me know if it works for you, it could be your problem. https://msdn.microsoft.com/en-us/library/aa384423.aspx

tasks:
    - name: Disable UAC Filtering for Local Accounts
      win_regedit: 
        data: 1
        datatype: dword
        key: "HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"
        value: LocalAccountTokenFilterPolicy
answered on Stack Overflow Aug 2, 2016 by Ionuț Maxim
0

What I ended up doing was to use the psexec module. It ran flawlessly when I used the same command you used, which also failed for me when using other ansible modules.

 - name: install sql
   win_psexec:
     command:  C:\Users\Administrator\Desktop\sql\Setup.exe /ConfigurationFile=C:\Users\Administrator\Desktop\ConfigurationFile.ini /INDICATEPROGRESS=False
     username: "{{Your_username}}"
     password: "{{Your_password}}"
     priority: high
     executable: "{{path_to_psexec.exe}}"
answered on Stack Overflow Jul 18, 2017 by Yuhan Zhou
0

Another approach to work around permissions could be to create a Windows Task and run that task with an account with Administrator permissions:

- name    : Create Install schtask
  raw     : "schtasks /create /tn \"SQLInstaller\" /tr C:\\SQL\\InstallSQLwithConfigIni.cmd /sd 01/01/1901 /ST 00:00 /sc ONCE /ru {{ansible_user}} /rp {{ansible_password}} /RL HIGHEST"

- name    : Run Install schtask now
  raw     : "schtasks /run /tn \"SQLInstaller\""

The contents of the InstallSQLwithConfigIni.cmd can be for example: C:\sql\SQLEXPR_x64_ENU.exe /Q /ConfigurationFile="C:\sql\Configuration.ini"

answered on Stack Overflow Jul 18, 2017 by brau
0

I think the issue and solution is captured within this page: https://github.com/ansible/ansible/issues/22660

It's all to do with "multi-hop".

It may depend on how you are authenticating to the Windows hosts, the link above suggested using CredSSP, although says Kerberos may also work.

answered on Stack Overflow Nov 14, 2017 by marc

User contributions licensed under CC BY-SA 3.0