How to override "winrm_username" in one of the provisioners

584 views
Skip to first unread message

Sayantan Choudhury

unread,
May 17, 2018, 4:03:33 PM5/17/18
to Packer
Hi,

I have a requirement where I need to build a Windows AMI in AWS and as per CIS recommendations, I need to rename the default windows Administrator username. I have multiple powershell provisioners in my build template and in one of the provisioners, I am changing the default windows Administrator username. I also have a requirement that I need to run provisioners after changing the default windows Administrator username. I am using winrm to connect to the EC2 machine and from the start, I am using the default windows Administrator username to connect.

After I change the default windows Administrator username, I need to somehow change the username to the new one. I was trying to use https://www.packer.io/docs/templates/provisioners.html#build-specific-overrides to override the "winrm_username" parameter, but that does not seem to work. Error: "* unknown configuration key: "winrm_username"". Same with any other configuration key that I use.

Please suggest if there is any other way to meet my requirements.

Rickard von Essen

unread,
May 17, 2018, 4:17:20 PM5/17/18
to packe...@googlegroups.com
That is not currently possible.

I think the only solution is to deley the change to the end. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/1cc25d83-8c4d-45e8-9312-4c7fa46bb7ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Megan Marsh

unread,
May 18, 2018, 12:29:18 PM5/18/18
to packe...@googlegroups.com
Alternatively, you can make the change in the script that you send in as your "user_data_file", before you run any provisioners.

On Thu, May 17, 2018 at 1:17 PM, Rickard von Essen <rickard....@gmail.com> wrote:
That is not currently possible.

I think the only solution is to deley the change to the end. 
On Thu, May 17, 2018, 22:03 Sayantan Choudhury <saya...@gmail.com> wrote:
Hi,

I have a requirement where I need to build a Windows AMI in AWS and as per CIS recommendations, I need to rename the default windows Administrator username. I have multiple powershell provisioners in my build template and in one of the provisioners, I am changing the default windows Administrator username. I also have a requirement that I need to run provisioners after changing the default windows Administrator username. I am using winrm to connect to the EC2 machine and from the start, I am using the default windows Administrator username to connect.

After I change the default windows Administrator username, I need to somehow change the username to the new one. I was trying to use https://www.packer.io/docs/templates/provisioners.html#build-specific-overrides to override the "winrm_username" parameter, but that does not seem to work. Error: "* unknown configuration key: "winrm_username"". Same with any other configuration key that I use.

Please suggest if there is any other way to meet my requirements.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt-uYW48F%3Dw9Dnp%2Bo3K05wesj5oSr6h-aqy2kjxTpNEDWw%40mail.gmail.com.
Message has been deleted

Sayantan Choudhury

unread,
May 18, 2018, 1:17:02 PM5/18/18
to Packer
@Megan - Could you please elaborate.

My requirement is to change the winrm_username between running 2 provisioners and the user_data_file runs only once when the instance starts.

Megan Marsh

unread,
May 18, 2018, 1:58:55 PM5/18/18
to packe...@googlegroups.com
You won't be able to change between provisioners. You can either change before the provisioners run, or at the very end--not in between. My comment was to point out that you can reset the Administrator password before the provisioners run and before Packer connects to the instance via WinRM

Alvaro Miranda Aguilera

unread,
May 20, 2018, 4:18:36 PM5/20/18
to packe...@googlegroups.com
hello

one simple way to do this is to get this into 2 steps

one that renames what you need and you grab this new AMI info
one that does the provisioning on this new ami with packer.

Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/1cc25d83-8c4d-45e8-9312-4c7fa46bb7ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Megan Marsh

unread,
May 21, 2018, 12:58:24 PM5/21/18
to packe...@googlegroups.com
Alvaro's right -- breaking this into two separate Packer runs is probably your best option.
Reply all
Reply to author
Forward
0 new messages