From: Frank Brehm Date: Tue, 19 Jul 2022 12:26:09 +0000 (+0200) Subject: Evaluate the puppet_initial_install flag for each VM X-Git-Tag: 1.6.8~2^2~3 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=741bab0e2c037c8bfb3e285d152fb286cab6f2c1;p=pixelpark%2Fcreate-terraform.git Evaluate the puppet_initial_install flag for each VM --- diff --git a/lib/cr_tf/handler.py b/lib/cr_tf/handler.py index fa76315..f2e16f8 100644 --- a/lib/cr_tf/handler.py +++ b/lib/cr_tf/handler.py @@ -64,7 +64,7 @@ from .terraform.disk import TerraformDisk from .xlate import XLATOR -__version__ = '3.7.2' +__version__ = '3.7.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -2778,6 +2778,8 @@ class CreateTerraformHandler(BaseHandler): cmd += "--project '{pr}' " cmd += "--role '{r}' --owner '{o}' --tier '{t}' --purpose '{p}' --email '{m}'" cmd += " --zone '{z}'" + if vm.puppet_initial_install: + cmd += " --initial-install" cmd = cmd.format( p=purpose, t=vm.puppet_tier, o=vm.customer, c=vm.puppet_customer, z=zone, pr=vm.puppet_project, m=vm.puppet_contact, e=vm.puppet_env, r=vm.puppet_role) diff --git a/lib/cr_tf/terraform/vm.py b/lib/cr_tf/terraform/vm.py index efb831a..2a0c6d6 100644 --- a/lib/cr_tf/terraform/vm.py +++ b/lib/cr_tf/terraform/vm.py @@ -37,7 +37,7 @@ from .disk import TerraformDisk, TerraformDiskDict from .interface import TerraformInterface -__version__ = '1.6.0' +__version__ = '1.6.1' LOG = logging.getLogger(__name__) @@ -154,7 +154,7 @@ class TerraformVm(HandlingObject): cluster=None, boot_delay=None, ds_cluster=None, datastore=None, ds_type=None, customer=None, rootdisk_size=None, purpose=None, puppet_contact=None, puppet_role=None, puppet_customer=None, puppet_project=None, puppet_tier=None, puppet_env=None, - puppet_initial_install=False, vm_template=None, nameservers=None, searchdomains=None, + puppet_initial_install=True, vm_template=None, nameservers=None, searchdomains=None, dns_options=None, has_backup=True, has_puppet=True, already_existing=None, vsphere=None): diff --git a/postinstall-scripts/init-puppet b/postinstall-scripts/init-puppet index 788e307..f7aa951 100755 --- a/postinstall-scripts/init-puppet +++ b/postinstall-scripts/init-puppet @@ -21,7 +21,7 @@ NORMAL="" HAS_TTY='y' HAS_COLORS="n" -VERSION="1.4" +VERSION="1.5" BASENAME="$(basename ${0})" BASE_DIR="$(dirname ${0})" @@ -42,6 +42,7 @@ PUPPET_BIN="/opt/puppetlabs/bin/puppet" PKG_INSTALLED="n" ROLE="base_oel7" PROJECT= +INITIAL_INSTALL="n" PUPPET_SERVER="puppetmaster.pixelpark.com" PUPPET_CA_SERVER="puppetca01.pixelpark.com" @@ -162,7 +163,7 @@ RM() { #------------------------------------------------------------------------------ description() { cat <<-EOF - Initialize a Puppet5 agent and start it. + Initialize a Puppet agent and start it. This script works only for Red Hat Linux and its derivates. @@ -194,6 +195,9 @@ usage() { -T|--tier TIER The tier of the production state. If not given, the Puppet environment will be used. -R|--role ROLE The Puppet role of the host, Default: '${ROLE}'. + -I|--initial-install + Set the custom fact initial_install for the first execution + of a Puppet agent run after deploying the VM. -P|--purpose PURPOSE The purpose of the host, Default: '${PURPOSE}'. -M|--email MAIL_ADDRESS @@ -242,9 +246,9 @@ get_options() { local tmp= local base_dir= - local short_options="E:C:p:O:T:R:P:M:l:z:dvqhV" + local short_options="E:C:p:O:T:R:IP:M:l:z:dvqhV" local long_options="env:,environment:,customer:,hiera-customer:,project:,owner:,tier:,role:," - long_options+="purpose:,server:,ca-server:,email:,location:,zone:," + long_options+="initial-install,purpose:,server:,ca-server:,email:,location:,zone:," long_options+="debug,verbose,quiet,help,version" set +e @@ -293,6 +297,10 @@ get_options() { shift shift ;; + -I|--initial-install) + INITIAL_INSTALL="y" + shift + ;; -P|--purpose) PURPOSE="$2" shift @@ -726,15 +734,17 @@ generate_facts() { debug "Generatet content of '${yfile}':\n${content}" echo "${content}" > "${yfile}" - yfile="${facts_dir}/initial_install.yaml" - info "Generating '${GREEN}${yfile}${NORMAL}' ..." - content=$( cat <<-EOF - --- - initial_install: true - EOF - ) - debug "Generatet content of '${yfile}':\n${content}" - echo "${content}" > "${yfile}" + if [[ "${INITIAL_INSTALL}" ]] ; then + yfile="${facts_dir}/initial_install.yaml" + info "Generating '${GREEN}${yfile}${NORMAL}' ..." + content=$( cat <<-EOF + --- + initial_install: true + EOF + ) + debug "Generatet content of '${yfile}':\n${content}" + echo "${content}" > "${yfile}" + fi wrong_file="${facts_dir}/host" if [[ -r "${wrong_file}" ]] ; then