Skip to content

Commit

Permalink
update ansible example (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
lmayorga1980 authored Dec 2, 2021
1 parent 497f0d7 commit 5358f91
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions docs/builders/googlecompute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,60 @@ build {
}
```

### Windows over WinSSH - Ansible Provisioner

The following uses Windows SSH as backend communicator
[https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse)
with a private key.

* The `windows-startup-script-cmd` creates the `packer_user` and adds it to the local administrators group and configures the ssh key, firewall rule and required permissions.

```
source "googlecompute" "windows-ssh-ansible" {
project_id = var.project_id
source_image = "windows-server-2019-dc-v20200813"
zone = "us-east4-a"
disk_size = 50
machine_type = "n1-standard-8"
communicator = "ssh"
ssh_username = var.packer_username
ssh_private_key_file = var.ssh_key_file_path
ssh_timeout = "1h"
metadata = {
windows-startup-script-cmd = "net user ${var.packer_username} \"${var.packer_user_password}\" /add /y & wmic UserAccount where Name=\"${var.packer_username}\" set PasswordExpires=False & net localgroup administrators ${var.packer_username} /add & powershell Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 & echo ${var.ssh_pub_key} > C:\\ProgramData\\ssh\\administrators_authorized_keys & icacls.exe \"C:\\ProgramData\\ssh\\administrators_authorized_keys\" /inheritance:r /grant \"Administrators:F\" /grant \"SYSTEM:F\" & powershell New-ItemProperty -Path \"HKLM:\\SOFTWARE\\OpenSSH\" -Name DefaultShell -Value \"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\" -PropertyType String -Force & powershell Start-Service sshd & powershell Set-Service -Name sshd -StartupType 'Automatic' & powershell New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 & powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"Set-ExecutionPolicy -ExecutionPolicy bypass -Force\""
}
account_file = var.account_file_path
}
build {
sources = ["sources.googlecompute.windows-ssh-ansible"]
provisioner "ansible" {
playbook_file = "./playbooks/playbook.yml"
use_proxy = false
ansible_ssh_extra_args = ["-o StrictHostKeyChecking=no -o IdentitiesOnly=yes"]
ssh_authorized_key_file = "var.public_key_path"
extra_arguments = ["-e", "win_packages=${var.win_packages}",
"-e",
"ansible_shell_type=powershell",
"-e",
"ansible_shell_executable=None",
"-e",
"ansible_shell_executable=None"
]
user = var.packer_username
}
}
```





### Nested Hypervisor Example

This is an example of using the `image_licenses` configuration option to create
Expand Down

0 comments on commit 5358f91

Please sign in to comment.