hashicorp / hashicorp/packer-plugin-azure

"basic: the specified credentials were rejected by the server", error thrown by the ansible

Open
#270 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
63
Forks
103
PR merge metrics
No merged PRs in 30d

Description

"basic: the specified credentials were rejected by the server", error thrown by the ansible when building an image from windows-2019 data center.

#### Overview of the Issue
"basic: the specified credentials were rejected by the server", error thrown by the ansible when building an image from windows-2019 data center.

#### Reproduction Steps

1. Enable WinRM over HTTP
2. Create an user ansible with a password
3. Use this credential to authenticate to Windows server

### Plugin and Packer version
packer >=1.7.8 using latest
azure plugin= 1.4.0
ansible plugin = 1.0.3

powershell script file used in provisioning step
net user ansible SuperS3cr3t!!! /add /expires:never
net localgroup administrators ansible /add
wmic useraccount where "name='ansible'" set PasswordExpires=FALSE
winrm quickconfig -quiet
winrm enumerate winrm/config/Listener
winrm get winrm/config/service
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/client/auth '@{Basic="true"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{CbtHardeningLevel="relaxed"}'
winrm get winrm/config/Service
winrm get winrm/config/Winrs
netsh advfirewall firewall add rule name= "Open Port 5985" dir=in action=allow protocol=TCP localport=5985

Write-Output '>>> Waiting for GA Service (RdAgent) to start ...'
while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }
Write-Output '>>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...'
while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service WindowsAzureTelemetryService).Status -ne 'Running')) { Start-Sleep -s 5 }
Write-Output '>>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...'
while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }
Write-Output '>>> Sysprepping VM ...'
if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
}
& $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
while($true) {
$imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
Write-Output $imageState
if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
Start-Sleep -s 5
}
Write-Output '>>> Sysprep complete ...'

packer file:

variable "subscription" {
type = string
}

variable "resource_group" {
type = string
}

variable "gallery_name" {
type = string
}

variable "image_name" {
type = string
}

variable "gallery_image_version" {
type = string
}

variable "replication_regions" {
type = list(string)
}

variable "storage_account_type" {
type = string
}

variable "image_publisher" {
type = string
}

variable "image_offer" {
type = string
}

variable "image_sku" {
type = string
}

variable "image_version" {
type = string
}

variable "vm_size" {
type = string
}

variable "vnet_name" {
type = string
}

variable "subnet_name" {
type = string
}

variable "vnet_resource_group" {
type = string
}

variable "gallery_resource_group" {
type = string
}

variable "images" {
type = map(object({
image_publisher = string
image_offer = string
image_sku = string
image_name = string
image_version = string
}))
}
source "azure-arm" "windows-image" {

private_virtual_network_with_public_ip = true
virtual_network_name = var.vnet_name
virtual_network_subnet_name = var.subnet_name
virtual_network_resource_group_name = var.vnet_resource_group

os_type = "Windows"
build_resource_group_name = "${var.resource_group}"
vm_size = "${var.vm_size}"

communicator = "winrm"
winrm_use_ssl = true
winrm_insecure = true
winrm_timeout = "5m"
winrm_username = "ansible"
winrm_password = "SuperS3cr3t!!!"

managed_image_name = "test-windows"
managed_image_resource_group_name = "${var.resource_group}"

use_azure_cli_auth = true
}

build {

dynamic "source" {
for_each = var.images
labels = ["azure-arm.windows-image"]
content {
name = source.key
image_publisher = source.value.image_publisher
image_offer = source.value.image_offer
image_sku = source.value.image_sku
image_version = source.value.image_version

#Push the Image to the Shared Image Gallery
shared_image_gallery_destination {
subscription = "${var.subscription}"
resource_group = "${var.gallery_resource_group}"
gallery_name = "${var.gallery_name}"
image_name = source.value.image_name
image_version = "${var.gallery_image_version}"
replication_regions = "${var.replication_regions}"
storage_account_type = "${var.storage_account_type}"
}

}
}

provisioner "powershell" {
script = "winrmscript.ps1"
}

provisioner "ansible" {
playbook_file = "playbooks/windows-playbook.yml"
roles_path = "playbooks/roles"
use_proxy = false
user = "ansible"
extra_arguments = ["--extra-vars", "ansible_user=ansible ansible_password=SuperS3cr3t!!! ansible_shell_type=powershell ansible_shell_executable=None","-vvvv"]
ansible_env_vars = [ "WINRM_PASSWORD={{.WinRMPassword}}"]
}
}

variables:
subscription = "xxxxxxxxxxxxxxxx"

resource_group = "airad-agentinfra"

gallery_resource_group = "airadosimage"

gallery_name = "computegallery1"

image_name = "windows-base-2022"

gallery_image_version = "1.0.0"

replication_regions = ["westeurope"]

storage_account_type = "Standard_LRS"

image_publisher = "MicrosoftWindowsServer"

image_offer = "WindowsServer"

image_sku = "2022-Datacenter"

image_version = "latest"

vm_size = "Standard_B2s"

vnet_name = "packer-vnet"

subnet_name = "packer-subnet"

vnet_resource_group = "agentinfra"

images = {
"windows-2022": {
"image_publisher" : "MicrosoftWindowsServer",
"image_offer" : "WindowsServer",
"image_sku" : "2022-Datacenter",
"image_version" : "latest"
"image_name": "windows-base-2022"
}
}

**Error:**

azure-arm.windows-2022: connection: smart
azure-arm.windows-2022: timeout: 10
azure-arm.windows-2022: become_method: sudo
azure-arm.windows-2022: tags: ('all',)
azure-arm.windows-2022: inventory: ('/tmp/packer-provisioner-ansible2639300242',)
azure-arm.windows-2022: extra_vars: ('packer_build_name="windows-image"', 'packer_builder_type=azure-arm', 'ansible_user=ansible ansible_password=SuperS3cr3t!!! ansible_shell_type=powershell ansible_shell_executable=None', 'ansible_password=SuperS3cr3t!!!')
azure-arm.windows-2022: forks: 5
azure-arm.windows-2022: 1 plays in /home/vsts/work/1/s/agent-infra/packer/playbooks/windows-playbook.yml
azure-arm.windows-2022:
azure-arm.windows-2022: PLAY [all] *********************************************************************
azure-arm.windows-2022:
azure-arm.windows-2022: TASK [basic-windows : Install git] *********************************************
azure-arm.windows-2022: task path: /home/vsts/work/1/s/agent-infra/packer/playbooks/roles/basic-windows/tasks/main.yml:2
azure-arm.windows-2022: redirecting (type: modules) ansible.builtin.win_chocolatey to chocolatey.chocolatey.win_chocolatey
azure-arm.windows-2022: redirecting (type: modules) ansible.builtin.win_chocolatey to chocolatey.chocolatey.win_chocolatey
azure-arm.windows-2022: Using module file /opt/pipx/venvs/ansible-core/lib/python3.10/site-packages/ansible_collections/chocolatey/chocolatey/plugins/modules/win_chocolatey.ps1
azure-arm.windows-2022: Pipelining is enabled.
azure-arm.windows-2022: <13.93.94.133> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO 13.93.94.133
azure-arm.windows-2022: failed: [default] (item=git) => {
azure-arm.windows-2022: "ansible_loop_var": "item",
azure-arm.windows-2022: "item": "git",
azure-arm.windows-2022: "msg": "basic: the specified credentials were rejected by the server",
azure-arm.windows-2022: "unreachable": true
azure-arm.windows-2022: }
azure-arm.windows-2022: redirecting (type: modules) ansible.builtin.win_chocolatey to chocolatey.chocolatey.win_chocolatey
azure-arm.windows-2022: redirecting (type: modules) ansible.builtin.win_chocolatey to chocolatey.chocolatey.win_chocolatey
azure-arm.windows-2022: Using module file /opt/pipx/venvs/ansible-core/lib/python3.10/site-packages/ansible_collections/chocolatey/chocolatey/plugins/modules/win_chocolatey.ps1
azure-arm.windows-2022: Pipelining is enabled.
azure-arm.windows-2022: <13.93.94.133> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO 13.93.94.133
azure-arm.windows-2022: failed: [default] (item=azure-pipelines-agent) => {
azure-arm.windows-2022: "ansible_loop_var": "item",
azure-arm.windows-2022: "item": "azure-pipelines-agent",
azure-arm.windows-2022: "msg": "basic: the specified credentials were rejected by the server",
azure-arm.windows-2022: "unreachable": true
azure-arm.windows-2022: }

Contributor guide

Open the contributing guide

Research direction

Start with the shown Azure ARM configuration, winrmscript.ps1, playbooks/windows-playbook.yml, and playbooks/roles/basic-windows/tasks/main.yml. Reproduce the Ansible WinRM connection using the listed versions and settings, then trace the authentication failure; done means identifying a verified configuration or plugin change that allows the Windows provisioning tasks to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
ansible, azure, powershell
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.