microsoft / VSTSAgent.PowerShell

Tools for managing and automating your Azure DevOps Agents.
MIT License
29 stars 23 forks source link

Failed to install VSTS Agent using DSC. #24

Closed mansing2 closed 4 years ago

mansing2 commented 4 years ago

I'm trying to install Agent using DSC but getting an error. Below is the DSC definition I'm using for the local test but keep on failing with error "ConvertTo-MOFInstance : System.InvalidOperationException error processing property 'AccountCredential' OF TYPE 'xVSTSAgent': Converting and storing encrypted passwords as plain text is not recommended. For more information on securing credentials in MOF file, please refer to MSDN blog: http://go.microsoft.com/fwlink/?LinkId=393729"

on the Azure side the error is "PowerShell DSC resource xVSTSAgent failed to execute Set-TargetResource functionality with error message: Could not find agent matching requirements."

My account that I use to login to DevOps (https://dev.azure.com/CO-Test) has MFA activated so not sure if that is the reason, it keeps on failing.


Configuration InstallVSTSAgent
{
     param 
    (   
        [parameter(Mandatory = $true)] 
        [PSCredential]$AccountCredential
    )

    Import-DSCResource -ModuleName 'VSTSAgent'

    xVSTSAgent VSTSAgent 
    {  
            Name              = 'Agent01'
            ServerUrl         = 'https://dev.azure.com/CO-Test'
            AccountCredential = $AccountCredential
            AgentDirectory    = 'C:\Agent'
            Work              = 'C:\VSTSAgentsWork\Agent01'
            Ensure            = 'Present' 
    }
}
  # Compile the configuration file to a MOF format
    InstallVSTSAgent

    # Run the configuration on localhost
    Start-DscConfiguration -Path .\InstallVSTSAgent -Wait -Force -Verbose```
jwittner commented 4 years ago

Hey @mansing2 - thanks for trying out the VSTS Agent DSC tooling! This is a common problem when using credentials in DSC.

Your exact error and how to work around it are described here: Credential Options in Configuration Data.

If you're leveraging Azure Automation, this documentation covers how to use their Credential Assets and how to configure support for the credentials in DSC.

Both of the above methods direct you to allow plain text passwords (safe if you run the dsc locally and safe in Azure Automation as the entire mof is encrypted at rest and in transit). There are other resources out there for how to encrypt your credentials or the mof for transit, but I'll leave that googling to the reader. =)