-
-
Save hteo1337/f5315070dd8f1ea8aa460fed1b39f38e to your computer and use it in GitHub Desktop.
Packer file to provision with ansible dynamic inventory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "variables": { | |
| "computename":"known-vm-name" | |
| }, | |
| "builders": [{ | |
| "type": "azure-arm", | |
| "subscription_id": "{{user `subscription_id`}}", | |
| "client_id": "{{user `client_id`}}", | |
| "client_secret": "{{user `client_secret`}}", | |
| "tenant_id": "{{user `tenant_id`}}", | |
| "managed_image_resource_group_name": "myrgrp", | |
| "managed_image_name": "thebox-packer-image", | |
| "os_type": "Windows", | |
| "image_publisher": "MicrosoftWindowsServer", | |
| "image_offer": "WindowsServer", | |
| "image_sku": "2016-Datacenter", | |
| "temp_compute_name":"{{user `computename`}}", | |
| "communicator": "winrm", | |
| "winrm_use_ssl": true, | |
| "winrm_insecure": true, | |
| "winrm_timeout": "15m", | |
| "winrm_username": "packer", | |
| "azure_tags": { | |
| "owner": "Brian Borncamp", | |
| "task": "Image deployment" | |
| }, | |
| "vm_size": "Standard_DS2_v2", | |
| "build_resource_group_name": "myrg", | |
| "virtual_network_name": "mynetwork-VNET", | |
| "virtual_network_resource_group_name": "mynetwork-RGRP", | |
| "virtual_network_subnet_name": "mynetworkSUB" | |
| }], | |
| "provisioners": [{ | |
| "type" : "powershell", | |
| "environment_vars": ["WINRMPASS={{.WinRMPassword}}","COMPUTE_NAME={{user `computename`}}"], | |
| "inline": [ | |
| "winrm set winrm/config/service/auth '@{Basic=\"true\"}'" | |
| ] | |
| }, | |
| { | |
| "type": "shell-local", | |
| "environment_vars": ["WINRMPASS={{.WinRMPassword}}","COMPUTE_NAME={{user `computename`}}"], | |
| "command": "echo \" - name != '$COMPUTE_NAME'\">>dynamic_azure_rm.yml" | |
| }, | |
| { | |
| "type" : "shell-local", | |
| "environment_vars": ["WINRMPASS={{.WinRMPassword}}","COMPUTE_NAME={{user `computename`}}"], | |
| "command": " ansible-playbook -vvv -i \"dynamic_azure_rm.yml\" -u packer -e ansible_password=\"$WINRMPASS\" -e@../variables/vars.yml ../playbooks/provisionedbox.yml" | |
| }, | |
| { | |
| "type" : "powershell", | |
| "environment_vars": ["WINRMPASS={{.WinRMPassword}}","COMPUTE_NAME={{user `computename`}}"], | |
| "inline": [ | |
| "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit", | |
| "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10 } else { break } }" | |
| ] | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment