-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f279ab5
commit 13c04ef
Showing
5 changed files
with
293 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/**/.* | ||
/**/.*/ | ||
!/.gitignore | ||
*-test.* | ||
main.sh | ||
main.yml | ||
goldenimage_script.sh | ||
manifest.json | ||
goldenimage_result.json |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# -*- mode: ruby -*- | ||
# vi: set ft=ruby : | ||
|
||
# vagrant plugin install vagrant-aws | ||
# vagrant up --provider=aws | ||
# vagrant destroy -f && vagrant up --provider=aws | ||
|
||
#-e "playbook_name=ansible-openvpn discord_message_owner_name=terra" | ||
MAIN_SCRIPT_URL = "https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/main_amzn2.sh" | ||
TOPIC_NAME = "errors" | ||
ACCOUNT_ID = "992382682634" | ||
AWS_REGION = "il-central-1" | ||
MAIN_SH_ARGS = <<MARKER | ||
-e "playbook_name=ansible-openvpn discord_message_owner_name=#{Etc.getpwuid(Process.uid).name}" | ||
MARKER | ||
Vagrant.configure("2") do |config| | ||
config.vm.provision "shell", inline: <<-SHELL | ||
set -euxo pipefail | ||
cd /vagrant | ||
bash parameters_exist.sh #{MAIN_SH_ARGS} | ||
# set -euxo pipefail | ||
# echo "start vagrant file" | ||
# source /deployment/ansibleenv/bin/activate | ||
# cd /deployment/playbook | ||
# export ANSIBLE_VERBOSITY=0 | ||
# export ANSIBLE_DISPLAY_SKIPPED_HOSTS=false | ||
# export VAULT_PASSWORD=#{`op read "op://Security/ansible-vault inqwise-stg/password"`.strip!} | ||
# echo "$VAULT_PASSWORD" > vault_password | ||
# bash main.sh #{MAIN_SH_ARGS} | ||
# rm vault_password | ||
# set -euxo pipefail | ||
# echo "start vagrant file" | ||
# yum -y erase python3 && amazon-linux-extras install python3.8 | ||
# python3.8 -m venv /tmp/ansibleenv | ||
# source /tmp/ansibleenv/bin/activate | ||
# aws s3 cp s3://resource-opinion-stg/get-pip.py - | python3.8 | ||
# cd /vagrant | ||
# export VAULT_PASSWORD=#{`op read "op://Security/ansible-vault inqwise-stg/password"`.strip!} | ||
# echo "$VAULT_PASSWORD" > vault_password | ||
# export ANSIBLE_VERBOSITY=0 | ||
# if [ ! -f "main.sh" ]; then | ||
# echo "Local main.sh not found. Download main.sh script from URL..." | ||
# curl -s https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/main_amzn2.sh -o main.sh | ||
# fi | ||
# bash main.sh #{MAIN_SH_ARGS} | ||
# rm vault_password | ||
SHELL | ||
|
||
config.vm.provider :aws do |aws, override| | ||
override.vm.box = "dummy" | ||
override.ssh.username = "ec2-user" | ||
override.ssh.private_key_path = "~/.ssh/id_rsa" | ||
aws.access_key_id = `op read "op://Security/aws inqwise-stg/Security/Access key ID"`.strip! | ||
aws.secret_access_key = `op read "op://Security/aws inqwise-stg/Security/Secret access key"`.strip! | ||
aws.keypair_name = Etc.getpwuid(Process.uid).name | ||
override.vm.allowed_synced_folder_types = [:rsync] | ||
#override.vm.synced_folder ".", "/vagrant", type: :rsync, rsync__exclude: ['.git/','inqwise/'], disabled: false | ||
#common_collection_path = ENV['COMMON_COLLECTION_PATH'] || '~/git/ansible-common-collection' | ||
#stacktrek_collection_path = ENV['COMMON_COLLECTION_PATH'] || '~/git/ansible-stack-trek' | ||
#override.vm.synced_folder common_collection_path + '/inqwise/common', '/vagrant/collections/ansible_collections/inqwise/common', type: :rsync, rsync__exclude: '.git/', disabled: false | ||
#override.vm.synced_folder stacktrek_collection_path + '/inqwise/stacktrek', '/vagrant/collections/ansible_collections/inqwise/stacktrek', type: :rsync, rsync__exclude: '.git/', disabled: false | ||
|
||
#aws.user_data = File.read("user_data.txt") | ||
aws.region = AWS_REGION | ||
aws.security_groups = ["sg-0cbd632d37524e9fe","sg-020afd8fd0fa9fd0b"] | ||
aws.ami = "ami-06df040a3b7ab6af4" | ||
aws.instance_type = "t3.micro" | ||
aws.subnet_id = "subnet-0f46c97c53ea11e2e" | ||
aws.associate_public_ip = true | ||
aws.iam_instance_profile_name = "bootstrap-role" | ||
aws.tags = { | ||
Name: "openvpn-test-#{Etc.getpwuid(Process.uid).name}", | ||
playbook_name: "ansible-openvpn", | ||
version: "latest", | ||
app: "openvpn", | ||
public_dns: "vpn-golden-test", | ||
private_dns: "vpn-golden-test" | ||
} | ||
end | ||
end | ||
|
||
#ami-00e65230f6b0a8dcf |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
//-on-error=abort | ||
// packer build --only=amazon-ebs.amzn2023_arm64 -var cpu_arch=arm64 -var 'aws_profile=opinion-stg' -var 'tag=latest' -var app=consul -var 'aws_region=il-central-1' . | ||
packer { | ||
required_plugins { | ||
amazon = { | ||
version = ">= 1.2.2" # preferably "~> 1.2.0" for latest patch version | ||
source = "github.com/hashicorp/amazon" | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
######## | ||
|
||
|
||
|
||
|
||
variable "cpu_arch" { | ||
description = "The CPU architecture type (e.g., arm64 or x86)." | ||
type = string | ||
default = "arm64" | ||
} | ||
|
||
variable "instance_type" { | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "base_path" { | ||
description = "The s3 base path to playbooks (e.g., s3://bootstrap-inqwise-org/playbooks)." | ||
type = string | ||
default = "s3://bootstrap-opinion-stg/playbooks" | ||
} | ||
|
||
variable "tag" { | ||
description = "The version of image" | ||
type = string | ||
} | ||
|
||
variable "aws_region" { | ||
type = string | ||
} | ||
|
||
variable "aws_iam_instance_profile" { | ||
type = string | ||
default = "PackerRole" | ||
} | ||
|
||
variable "aws_profile" { | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "app" { | ||
description = "The app name. for example 'consul'" | ||
type = string | ||
} | ||
|
||
|
||
|
||
######## | ||
|
||
|
||
|
||
locals { | ||
instance_types = { | ||
arm64 = var.instance_type != "" ? var.instance_type : "t4g.small" | ||
x86 = var.instance_type != "" ? var.instance_type : "t3.small" | ||
} | ||
|
||
common_build_settings = { | ||
shell_provisioners = { | ||
inline = !fileexists("goldenimage-test.sh") ? [ | ||
"curl --connect-timeout 2.37 -m 20 -o /tmp/parameters_find.sh https://raw.githubusercontent.com/xXkoshmarikXx/test-commit/master/parameters_find.sh && bash /tmp/parameters_find.sh --tags installation", | ||
] : [], | ||
scripts = fileexists("goldenimage-test.sh") ? [ | ||
"goldenimage-test.sh" | ||
] : [] | ||
} | ||
|
||
post_processors = { | ||
manifest = { | ||
type = "manifest" | ||
output = "manifest.json" | ||
strip_path = true | ||
custom_data = { | ||
app = var.app | ||
version = var.tag | ||
profile = var.aws_profile | ||
region = var.aws_region | ||
} | ||
} | ||
} | ||
} | ||
|
||
timestamp = formatdate("YYYYMMDDhhmm", timestamp()) | ||
} | ||
|
||
|
||
|
||
######## | ||
|
||
|
||
|
||
source "amazon-ebs" "common" { | ||
force_deregister = true | ||
force_delete_snapshot = true | ||
ami_name = "${var.app}-${var.tag}" | ||
ami_description = "Image of ${var.app} version ${var.tag}" | ||
spot_instance_types = ["${local.instance_types[var.cpu_arch]}"] | ||
region = "${var.aws_region}" | ||
#ami_regions = ["us-west-2"] | ||
#ami_users = ["123456789012", "987654321098"] # List of AWS Account IDs granted launch permissions for the created AMI | ||
encrypt_boot = false | ||
profile = "${var.aws_profile}" | ||
iam_instance_profile = "${var.aws_iam_instance_profile}" | ||
ssh_username = "ec2-user" | ||
spot_price = "auto" | ||
skip_create_ami = false # for debug | ||
|
||
metadata_options { | ||
instance_metadata_tags = "enabled" | ||
http_endpoint = "enabled" | ||
http_put_response_hop_limit = "1" | ||
http_tokens = "required" | ||
} | ||
|
||
run_tags = { | ||
Name = "${var.app}-${var.tag}-packer" | ||
app = "${var.app}" | ||
version = "${var.tag}" | ||
timestamp = "${local.timestamp}" | ||
playbook_name = "ansible-${var.app}" | ||
} | ||
|
||
tags = { | ||
Name = "${var.app}-${var.tag}" | ||
app = "${var.app}" | ||
version = "${var.tag}" | ||
timestamp = "${local.timestamp}" | ||
} | ||
} | ||
|
||
build { | ||
source "source.amazon-ebs.common" { | ||
name = "amzn2023_arm64" | ||
source_ami_filter { | ||
filters={ | ||
name = "al2023-ami-2023.*-kernel-6.1-arm64" | ||
root-device-type = "ebs" | ||
virtualization-type = "hvm" | ||
} | ||
most_recent = true | ||
owners = ["amazon"] | ||
} | ||
} | ||
|
||
source "source.amazon-ebs.common" { | ||
name = "amzn2_x86" | ||
source_ami_filter { | ||
filters={ | ||
name = "amzn2-ami-kernel-5.*-x86_64-gp2" | ||
root-device-type = "ebs" | ||
virtualization-type = "hvm" | ||
} | ||
most_recent = true | ||
owners = ["amazon"] | ||
} | ||
} | ||
|
||
provisioner "shell" { | ||
scripts = local.common_build_settings.shell_provisioners.scripts | ||
inline = local.common_build_settings.shell_provisioners.inline | ||
} | ||
|
||
post-processor "manifest" { | ||
output = local.common_build_settings.post_processors.manifest.output | ||
strip_path = local.common_build_settings.post_processors.manifest.strip_path | ||
custom_data = local.common_build_settings.post_processors.manifest.custom_data | ||
} | ||
|
||
post-processor "shell-local" { | ||
inline = [ | ||
"if [ -f ./goldenimage-postprocess-test.sh ]; then", | ||
" echo 'Executing local script: goldenimage-postprocess-test.sh';", | ||
" bash ./goldenimage-postprocess-test.sh;", | ||
"else", | ||
" echo 'Local script not found. Executing remote script: https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/packer/goldenimage-postprocess.sh';", | ||
" curl -s https://raw.githubusercontent.com/inqwise/ansible-automation-toolkit/default/packer/goldenimage-postprocess.sh | bash;", | ||
"fi" | ||
] | ||
} | ||
} |
This file contains 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
This file contains 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