-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pkr.hcl
75 lines (64 loc) · 1.58 KB
/
main.pkr.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
packer {
required_plugins {
amazon = {
version = "~> 1.3"
source = "github.com/hashicorp/amazon"
}
ansible = {
version = "~> 1.1"
source = "github.com/hashicorp/ansible"
}
}
required_version = "~> 1.11"
}
data "amazon-ami" "rhel9" {
region = var.region
filters = var.ami_filter
most_recent = true
owners = [var.ami_owner]
}
locals {
timestamp = formatdate("YYYY-MM-DD_hh-mm-ss", timestamp())
ami_name = "${var.ami_name}_${local.timestamp}"
}
source "amazon-ebs" "img" {
ami_name = local.ami_name
instance_type = var.instance_type
region = var.region
source_ami = data.amazon-ami.rhel9.id
ssh_username = var.ssh_username
}
build {
name = var.ami_name
hcp_packer_registry {
bucket_name = var.ami_name
description = "Base RHEL 9 AMI with Ansible Automation Platform installer package preloaded."
bucket_labels = {
owner = "Dustin Dortch"
os = "RHEL"
version = "9"
}
build_labels = {
timestamp = local.timestamp
}
}
provisioner "ansible" {
playbook_file = "playbook.yml"
sftp_command = "/usr/libexec/openssh/sftp-server -e"
ansible_env_vars = [
"ANSIBLE_DEPRECATION_WARNINGS=False",
"ANSIBLE_HOST_KEY_CHECKING=False",
"ANSIBLE_NOCOLOR=True",
"ANSIBLE_NOCOWS=1"
]
extra_arguments = [
"--ssh-extra-args",
"-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -o IdentitiesOnly=yes",
"--scp-extra-args",
"'-O'"
]
}
sources = [
"source.amazon-ebs.img"
]
}