packer - using different communicator credentials in a provisioner

15 views
Skip to first unread message

Frank.Lapierre

unread,
Aug 6, 2019, 3:47:05 PM8/6/19
to Packer
Hi All,

I'm trying to fully automate a Windows 10 build using Packer. I'm mostly successful, with the exception of patching the OS before I generate the AMI/VM template.

I don't know if that's feasible or how to approach this, but here's what I'm trying:

1. Use specific WINRM credentials before my VM is joined to the domain.
2. After it is joined to the domain, use new credentials to keep interacting with the VM.

Since I can't specify a different communicator within the "provisioners" block, I'm not sure how I could do this? Reason I need to join the domain is because windows won't patch if it is not activated.

Invalid example (as I specified communicator info in the provisioner):

builder:
...
      "communicator": "winrm",
      "winrm_use_ssl": true,
      "winrm_insecure": true,
      "winrm_use_ntlm": true,
      "winrm_username": "Administrator",
      "winrm_password": "Password1",
...

  "provisioners": [
    {
      "type": "powershell",
      "environment_vars": [
        "vm_hostname={{user `vm_hostname`}}"
      ],
      "inline": ["Rename-Computer -NewName \"$env:vm_hostname\""]
    },
    { "type": "windows-restart",
      "pause_before": "30s"
    },
    {
      "type": "powershell",
      "script": "{{template_dir}}/join-domain.ps1",
      "environment_vars": [
        "vm_hostname={{user `vm_hostname`}}",
        "ad_domain={{user `ad_domain`}}",
        "ad_ou_path={{user `ad_ou_path`}}",
        "ad_domain_user=DOMAIN\\user",
        "ad_domain_pw=DOMAIN\\password"
      ]
    }
  ],
    "provisioners": [
    {
      "communicator": "winrm",
      "winrm_use_ssl": true,
      "winrm_insecure": true,
      "winrm_use_ntlm": true,
      "winrm_username": "{{ user `ad_username` }}",
      "winrm_password": "{{ user `ad_password` }}",
      "type": "windows-restart",
      "pause_before": "30s"
    }
  ]
}

Thanks!

Megan Marsh

unread,
Aug 12, 2019, 2:33:50 PM8/12/19
to packe...@googlegroups.com
We have a known issue with domain-joins not working because they mess up Packer's connection, but I haven't had a chance to investigate. Sorry :(
Reply all
Reply to author
Forward
0 new messages