Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update ansible example #65

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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