Skip to content

Instantly share code, notes, and snippets.

@bugcy013
Created December 12, 2021 01:48
Show Gist options
  • Save bugcy013/dbf63c73cdf9da6de3a45a1b66e8cdc1 to your computer and use it in GitHub Desktop.
Save bugcy013/dbf63c73cdf9da6de3a45a1b66e8cdc1 to your computer and use it in GitHub Desktop.
# This file was autogenerated by the 'packer hcl2_upgrade' command. We
# recommend double checking that everything is correct before going forward. We
# also recommend treating this file as disposable. The HCL2 blocks in this
# file can be moved to other files. For example, the variable blocks could be
# moved to their own 'variables.pkr.hcl' file, etc. Those files need to be
# suffixed with '.pkr.hcl' to be visible to Packer. To use multiple files at
# once they also need to be in the same folder. 'packer inspect folder/'
# will describe to you what is in that folder.
# Avoid mixing go templating calls ( for example ```{{ upper(`string`) }}``` )
# and HCL2 calls (for example '${ var.string_value_example }' ). They won't be
# executed together and the outcome will be unknown.
# All generated input variables will be of 'string' type as this is how Packer JSON
# views them; you can change their type later on. Read the variables type
# constraints documentation
# https://www.packer.io/docs/templates/hcl_templates/variables#type-constraints for more info.
variable "client_id" {
type = string
default = "${env("ARM_CLIENT_ID")}"
}
variable "client_secret" {
type = string
default = "${env("ARM_CLIENT_SECRET")}"
}
variable "subscription_id" {
type = string
default = "${env("ARM_SUBSCRIPTION_ID")}"
}
variable "tenant_id" {
type = string
default = "${env("ARM_TENANT_ID")}"
}
# source blocks are generated from your builders; a source can be referenced in
# build blocks. A build block runs provisioner and post-processors on a
# source. Read the documentation for source blocks here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/source
source "azure-arm" "autogenerated_1" {
azure_tags = {
application = ""
costcode = ""
department = ""
managed_by = "ansible"
os = "ubuntu"
owner = ""
platform = "linux"
}
client_id = "${var.client_id}"
client_secret = "${var.client_secret}"
image_offer = "UbuntuServer"
image_publisher = "Canonical"
image_sku = "18.04-LTS"
location = "westeurope"
managed_image_name = "lab6"
managed_image_resource_group_name = "images"
os_type = "Linux"
shared_image_gallery_destination {
gallery_name = "sharedImageGallery"
image_name = "ubuntu_standard"
image_version = "1.0.0"
replication_regions = ["westeurope", "uaenorth", "southafricanorth"]
resource_group = "images"
}
subscription_id = "${var.subscription_id}"
tenant_id = "${var.tenant_id}"
vm_size = "Standard_B1s"
}
# a build block invokes sources and runs provisioning steps on them. The
# documentation for build blocks can be found here:
# https://www.packer.io/docs/templates/hcl_templates/blocks/build
build {
sources = ["source.azure-arm.autogenerated_1"]
provisioner "ansible" {
ansible_env_vars = ["ANSIBLE_HOST_KEY_CHECKING=False", "ANSIBLE_SSH_ARGS='-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s'", "ANSIBLE_NOCOLOR=True", "ANSIBLE_NOCOWS=1"]
playbook_file = "/etc/ansible/standard.yml"
user = "packer"
}
provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
expect_disconnect = "true"
inline = [" /sbin/reboot --reboot --no-wall"]
pause_after = "10s"
timeout = "1m40s"
}
provisioner "shell" {
execute_command = "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'"
inline = ["/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"]
inline_shebang = "/bin/sh -x"
pause_before = "10s"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment