diff --git a/openstack.pkrvars.hcl.example b/openstack.pkrvars.hcl.example index 7771e06324c7574298e7d3314ca204e481614734..7f2a2f9d3137eeada3fee7a862db5a69927a39de 100644 --- a/openstack.pkrvars.hcl.example +++ b/openstack.pkrvars.hcl.example @@ -12,3 +12,17 @@ security_groups = ["allow ssh"] image_date_suffix = false # Set to a public key that will be added as a root ssh key root_ssh_key = "ecdsa-sha2-nistp256 AAAAyourkeyhere comment string here" +# Create image at the end of build. Set to true during a build test stage +skip_create_image = false +# Project/tenants to share the image with +image_membership = [] +# Auto accept image on behalf of members. Need privileges both in build project and members provided +auto_accept_members = false +# Tags for the resulting image. +image_tags = [] +# The username to connect to SSH with. Used by Packer build section +ssh_username = "centos" +# Key that will be used for SSH with the machine. Must match key pair name loaded up into the remote. +ssh_keypair_name = "" +# Path to the private key file to use to authenticate with SSH. +ssh_private_key_file = "" diff --git a/openstack/nodeimage.pkr.hcl b/openstack/nodeimage.pkr.hcl index 5e4a24586bebf4c08bc15a0f2e78d581d1cf6c4b..5cc075a38b0385988c1b1a1876c04712863d6d53 100644 --- a/openstack/nodeimage.pkr.hcl +++ b/openstack/nodeimage.pkr.hcl @@ -3,15 +3,23 @@ locals { } source "openstack" "image" { + skip_create_image = var.skip_create_image image_name = local.local_image_name source_image_name = var.source_image + image_members = var.image_membership + image_auto_accept_members = var.auto_accept_members + image_tags = var.image_tags flavor = var.flavor + instance_name = var.build_instance_name floating_ip_network = var.floating_ip_network networks = var.networks security_groups = var.security_groups ssh_username = var.ssh_username + ssh_keypair_name = var.ssh_keypair_name + ssh_private_key_file = var.ssh_private_key_file + } build { @@ -24,4 +32,18 @@ build { "--extra-vars", "root_ssh_key='${var.root_ssh_key}'" ] } + provisioner "ansible" { + use_proxy = false + ssh_authorized_key_file = "/home/ubuntu/.ssh/id_rsa.pub" + ansible_env_vars = ["ANSIBLE_HOST_KEY_CHECKING=False"] + playbook_file = "../CRI_XCBC/ood-packer.yaml" + roles_path = "./ansible/roles" + inventory_file = "../CRI_XCBC/hosts" + extra_arguments = [ + "--extra-vars", "root_ssh_key='${var.root_ssh_key}'", + "--private-key=${var.ssh_private_key_file}", + "--user=centos", + #"-vvvv" + ] + } } diff --git a/openstack/variables.pkr.hcl b/openstack/variables.pkr.hcl index 454bdc5b295cc05225b13f45480c72776edfeb09..175ca17edf8b952ec5a041cc8209720473d2ac8d 100644 --- a/openstack/variables.pkr.hcl +++ b/openstack/variables.pkr.hcl @@ -15,6 +15,30 @@ variable "image_date_suffix" { description = "Append a date to the image name (in YYYYMMDDHHMMSS format)" } +variable "image_tags" { + type = list(string) + default = [] + description = "List of tags to be associated to the resulting image" +} + +variable "image_membership" { + type = list(string) + default = [] + description = "Projects/tenants to share the image in openstack with" +} + +variable "auto_accept_members" { + type = bool + default = false + description = "A boolean value for auto accepting image in the projects/tenants defined in image_membership." +} + +variable "skip_create_image" { + type = bool + default = false + description = "A boolean value for skipping image creation at the end of the build" +} + variable "source_image" { type = string description = "The name of the source image to use" @@ -25,12 +49,6 @@ variable "flavor" { description = "The name of the flavor to use" } -variable "ssh_username" { - type = string - default = "centos" - description = "The default username to use for SSH" -} - variable "floating_ip_network" { type = string description = "floating ip network to use with (temporary) ip assignmnet to a vm" @@ -46,3 +64,25 @@ variable "security_groups" { default = [] description = "A list of security groups to add - you should make sure ssh access is open to the machine" } + +variable "build_instance_name" { + type = string + default = "ood" + description = "A name of build instance used for image build" +} + +variable "ssh_username" { + type = string + default = "centos" + description = "The default username to use for SSH" +} + +variable "ssh_keypair_name" { + type = string + description = "SSH keypair to use from OS project" +} + +variable "ssh_private_key_file" { + type = string + description = "Private key file" +}