From 0247cfa398e6e44c53e9dfccd25276827b0e9484 Mon Sep 17 00:00:00 2001 From: Marcin Bojko Date: Mon, 30 Sep 2019 17:35:39 +0200 Subject: [PATCH] Version 1.0.9 --- CHANGELOG.md | 9 + README.md | 53 ++++-- extra/README.md | 30 ---- extra/files/gen1-vb/1903/Autounattend.xml | 154 ++++++++++++++++ extra/files/gen1-vb/1903/unattend.xml | 53 ++++++ extra/files/gen2-centos/ks.cfg | 1 + extra/files/gen2-centos/prepare_neofetch.sh | 10 +- extra/files/gen2-centos/provision.sh | 166 ++++++++++++++---- extra/files/gen2-centos/zeroing.sh | 3 +- extra/scripts/phase-1.ps1 | 33 +++- extra/scripts/phase-2.ps1 | 33 +++- extra/scripts/phase-3.ps1 | 2 +- extra/scripts/phase-5b.docker.ps1 | 2 +- hv_centos76_g2.cmd | 5 +- hv_centos76_g2_docker.cmd | 4 +- hv_centos77_g2.cmd | 4 + hv_centos77_g2_docker.cmd | 5 + hv_centos77_g2_vagrant.cmd | 4 + ...s76_g2_vagrant.json => hv_centos7_g2.json} | 60 ++----- ..._docker.json => hv_centos7_g2_docker.json} | 42 ++--- ...s76_g2.json => hv_centos7_g2_vagrant.json} | 60 ++++--- vagrant/hv_centos77_g2.template | 27 +++ vagrant_hv_centos76_g2.cmd | 3 - validate_all.sh | 11 -- variables/variables_centos76.json | 15 ++ variables/variables_centos77.json | 15 ++ 26 files changed, 583 insertions(+), 221 deletions(-) delete mode 100644 extra/README.md create mode 100644 extra/files/gen1-vb/1903/Autounattend.xml create mode 100755 extra/files/gen1-vb/1903/unattend.xml create mode 100755 hv_centos77_g2.cmd create mode 100755 hv_centos77_g2_docker.cmd create mode 100755 hv_centos77_g2_vagrant.cmd rename templates/{hv_centos76_g2_vagrant.json => hv_centos7_g2.json} (70%) rename templates/{hv_centos76_g2_docker.json => hv_centos7_g2_docker.json} (80%) rename templates/{hv_centos76_g2.json => hv_centos7_g2_vagrant.json} (78%) create mode 100644 vagrant/hv_centos77_g2.template delete mode 100755 vagrant_hv_centos76_g2.cmd delete mode 100755 validate_all.sh create mode 100644 variables/variables_centos76.json create mode 100644 variables/variables_centos77.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 14fab91..671dc7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## Version 1.0.9 2019-09-30 + +* [BREAKING CHANGE] - CentOS Machines now support templating and previous version creation + * all CentOS deploys now consists of main template file (./templates) and var_file (./variables). This will allow to have more than 'latest' version of release when needed. +* [Extra] reworked scripts +* [CentOS] Upgrade Zabbix repository (4.2) +* [CentOS] Provision script now supports flags to install or not specific portion of packages. +* [Windows] Upgrade to dotnetfx chocolatey package (.net 4.8 by default) + ## Version 1.0.8 2019-05-25 * switch to packer `1.4` branch - be aware of syntax changes diff --git a/README.md b/README.md index 41c6a86..9a6b444 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ ## Requirements -* packer <=`1.4.1`. Do not use packer below 1.4.0. For previous packer versions use previous releases from this repository -* [OPTIONAL] Vagrant >= `2.2.3` +* packer <=`1.4.3`. Do not use packer below 1.4.0. For previous packer versions use previous releases from this repository * Microsoft Hyper-V Server 2016/2019 or Microsoft Windows Server 2016/2019 (not 2012/R2) +* [OPTIONAL] Vagrant >= `2.2.5` - for `vagrant` version of scripts ## Usage ### Install packer from Chocolatey ```cmd -choco install packer --version=1.4.1 +choco install packer --version=1.4.3 ``` ### Add firewal exclusions for TCP ports 8000-9000 (default range) @@ -22,7 +22,7 @@ New-NetFirewallRule -DisplayName "Packer_http_server" -Direction Inbound -Action ``` -### To adjust to your Hyper-V, please check variables below: +### To adjust to your Hyper-V, please check variables below * proper VLAN (possible passing as variable `-var 'vlan_id=0'` ) * proper Hyper-V Virtual Switch name (access to Internet will be required) (possible passing as variable `-var 'switch_name=vSwitch'` ) @@ -32,8 +32,6 @@ New-NetFirewallRule -DisplayName "Packer_http_server" -Direction Inbound -Action ### Scripts -* `validate_all.sh` - validates all templates. - ### Windows Machines * all available updates will be applied (3 passes) @@ -42,9 +40,9 @@ New-NetFirewallRule -DisplayName "Packer_http_server" -Direction Inbound -Action |Package|Version| |-------|-------| - |puppet-agent|5.5.12| + |puppet-agent|5.5.16| |conemu|latest| - |dotnet4.7.2|latest| + |dotnetfx|latest| |sysinternals|latest| * latest Nuget poweshell module * puppet agent settings will be customized (`server=foreman.spcph.local`). Please adjust it (`/extra/scripts/phase-3.ps1`) to suit your needs. Puppet won't be running after generalize phase @@ -53,16 +51,27 @@ New-NetFirewallRule -DisplayName "Packer_http_server" -Direction Inbound -Action * Repositories: * EPEL 7 - * Zabbix 4.x - * Puppet 5.x - * Webmin + * Zabbix 4.2 + * Puppet 5.x [can be switch off by -p false] + * Webmin/Usermin (can be switched off by setting ) * Neofetch * latest System Center Virtual Machine Agent available (with versioning, so you always can go back) #### Info -* adjust `/files/provision.sh` to modify package's versions/servers -* `neofetch` packageas default banner during after the login - change required fields you'd like to see in `provision.sh` +* adjust `/files/provision.sh` to modify package's versions/servers. +* change "provision_script_options" variable to: + * -p (true/false) - switch Install Puppet on/off + * -w (true/false) - switch Install Webmin on/off + * -h (true/false) - switch Install Hyper-V integration services on/off + * -u (true/false) - switch yum update all on/off (usable when creating previous than `latest` version of OS) +Example: + +```json +"provision_script_options": "-p false -u true -w true -h false" +``` + +* `prepare_neofetch.sh` default banner during after the login - change required fields you'd like to see in `provision.sh` ## Templates Windows 2016 @@ -162,9 +171,13 @@ Run `hv_win2016_1809_g2.cmd` (Windows) ## Templates CentOS 7.x +### Hyper-V Generation 2 CentOS 7.7 Image + +Run `hv_centos77_g2.cmd` + ### Hyper-V Generation 2 CentOS 7.6 Image -Run `hv_centos76_g2.cmd` (Windows) +Run `hv_centos77_g2.cmd` ### Warnings - CentOS @@ -179,11 +192,15 @@ Run `hv_centos76_g2.cmd` (Windows) ### Vagrant support -Experimental support for vagrant machines `vagrant_hv_centos76_g2.cmd` +Experimental support for vagrant machines `hv_centos76_g2_vagrant.cmd` + +### Hyper-V Generation 2 CentOS 7.7 Image with extra docker volume + +Run `hv_centos77_g2_docker.cmd` ### Hyper-V Generation 2 CentOS 7.6 Image with extra docker volume -Run `hv_centos76_g2_docker.cmd` (Windows) +Run `hv_centos76_g2_docker.cmd` ### Warnings - CentOS Docker @@ -204,7 +221,7 @@ Run `hv_centos76_g2_docker.cmd` (Windows) During the deployment secure keys are stored in *.vmcx file and are separated from *.vhdx file. To countermeasure it - there is added extra step in a form of (`/usr/local/bin/uefi.sh`) script that will check for existence of CentOS folder in EFI and will add extra entry in UEFI. In manual setup you can run it as a part of your deploy. In SCVMM deployment I'd recommend using `RunOnce` feature. -### On Windows Server 2019/Windows 10 1809 image boots to fast for packer to react. +### On Windows Server 2019/Windows 10 1809 image boots to fast for packer to react [https://github.com/hashicorp/packer/issues/7278#issuecomment-468492880](https://github.com/hashicorp/packer/issues/7278#issuecomment-468492880) @@ -223,7 +240,7 @@ No resolution so far, template needs to be changed to pass real IP address, or t [https://github.com/hashicorp/packer/issues/5023](https://github.com/hashicorp/packer/issues/5023) Will be fixed in 1.4.x revision -### I have problem how to find a proper WIM name in Windows ISO to pick proper version. +### I have problem how to find a proper WIM name in Windows ISO to pick proper version You can use number. If you have 4 images on the list of choice - use `ImageIndex` with proper `Value` diff --git a/extra/README.md b/extra/README.md deleted file mode 100644 index 71c1308..0000000 --- a/extra/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# Set of various shared scripts and files for packer templates - -## 2019-03-04 - -* disabled `Install-WindowsFeature NET-Framework-Core,NET-Framework-Features,PowerShell-V2 -IncludeManagementTools` in phase-1.ps1 script. - -## 2018-12-29 - -* [Windows] reworked `phase-1.ps1` script to recognise Windows version to adjust proper config for it -* [Windows] reworked `phase-1.ps1` removed Spectre/Meltdown migitation entries - -## 2018-12-03 - -* [CentOS] remove port 8140 from firewalld configuration -* [CentOS] change zabbix repository to version 4.x (won't work with Zabbix server below 4.x) -* [CentOS] added log cleaning/rotating after build -* [CentOS] upgraded SCVMM agent to version 1.0.3.1022. For older SCVMM older agent (1.0.2) is also available -* [Windows] lock `puppet-agent` on version 5.5.8 -* [Windows] set `Disable-WindowsErrorReporting` for Windows based machines - -## 2018-11-08 - -* [Windows] puppet version set to 5.5.7 -* [Windows] disable Windows Error Reporting. - -## 2018-05-31 - -### CentOS - -* added telnet ncdu screen to `provision.sh` diff --git a/extra/files/gen1-vb/1903/Autounattend.xml b/extra/files/gen1-vb/1903/Autounattend.xml new file mode 100644 index 0000000..5ec419d --- /dev/null +++ b/extra/files/gen1-vb/1903/Autounattend.xml @@ -0,0 +1,154 @@ + + + + + + en-US + + en-US + en-US + en-US + en-US + en-US + + + + + + + Primary + 1 + 350 + + + 2 + Primary + true + + + + + true + NTFS + + 1 + 1 + + + NTFS + + C + 2 + 2 + + + 0 + true + + + + + + + /IMAGE/INDEX + 1 + + + + 0 + 2 + + + + + + + OnError + + true + Vagrant + Hashicorp + + + + + + + false + + vagrant-1903 + Pacific Standard Time + + + + true + + + false + false + + + true + + + + + + + vagrant + true</PlainText> + </Password> + <Enabled>true</Enabled> + <Username>vagrant</Username> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> + <Description>Set Execution Policy 64 Bit</Description> + <Order>1</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>C:\Windows\SysWOW64\cmd.exe /c powershell -Command "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force"</CommandLine> + <Description>Set Execution Policy 32 Bit</Description> + <Order>2</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\bootstrap.ps1</CommandLine> + <Description>Fix public network</Description> + <Order>3</Order> + <RequiresUserInput>true</RequiresUserInput> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>cmd.exe /c wmic useraccount where "name='vagrant'" set PasswordExpires=FALSE</CommandLine> + <Order>4</Order> + <Description>Disable password expiration for vagrant user</Description> + </SynchronousCommand> + </FirstLogonCommands> + <UserAccounts> + <AdministratorPassword> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </AdministratorPassword> + <LocalAccounts> + <LocalAccount wcm:action="add"> + <Password> + <Value>vagrant</Value> + <PlainText>true</PlainText> + </Password> + <DisplayName>Vagrant User</DisplayName> + <Group>Administrators</Group> + <Name>vagrant</Name> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + </component> + </settings> + <settings pass="offlineServicing"> + <component name="Microsoft-Windows-LUA-Settings" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <EnableLUA>false</EnableLUA> + </component> + </settings> + <cpi:offlineImage cpi:source="wim://vboxsrv/vagrant/iso%202016/sources/install.wim#Windows Server 2016 Technical Preview 5 SERVERSTANDARD" xmlns:cpi="urn:schemas-microsoft-com:cpi" /> +</unattend> diff --git a/extra/files/gen1-vb/1903/unattend.xml b/extra/files/gen1-vb/1903/unattend.xml new file mode 100755 index 0000000..3e719d6 --- /dev/null +++ b/extra/files/gen1-vb/1903/unattend.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<unattend xmlns="urn:schemas-microsoft-com:unattend"> + <settings pass="generalize"> + <component name="Microsoft-Windows-Security-SPP" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <SkipRearm>1</SkipRearm> + </component> + <component name="Microsoft-Windows-PnpSysprep" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <PersistAllDeviceInstalls>false</PersistAllDeviceInstalls> + <DoNotCleanUpNonPresentDevices>false</DoNotCleanUpNonPresentDevices> + </component> + </settings> + <settings pass="oobeSystem"> + <component name="Microsoft-Windows-International-Core" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <InputLocale>en-US</InputLocale> + <SystemLocale>en-US</SystemLocale> + <UILanguage>en-US</UILanguage> + <UserLocale>en-US</UserLocale> + </component> + <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <ProtectYourPC>1</ProtectYourPC> + <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> + </OOBE> + <TimeZone>UTC</TimeZone> + <UserAccounts> + <AdministratorPassword> + <Value>dgBhAGcAcgBhAG4AdABBAGQAbQBpAG4AaQBzAHQAcgBhAHQAbwByAFAAYQBzAHMAdwBvAHIAZAA=</Value> + <PlainText>false</PlainText> + </AdministratorPassword> + <LocalAccounts> + <LocalAccount wcm:action="add"> + <Password> + <Value>dgBhAGcAcgBhAG4AdABQAGEAcwBzAHcAbwByAGQA</Value> + <PlainText>false</PlainText> + </Password> + <Group>administrators</Group> + <DisplayName>Vagrant</DisplayName> + <Name>vagrant</Name> + <Description>Vagrant User</Description> + </LocalAccount> + </LocalAccounts> + </UserAccounts> + </component> + </settings> + <settings pass="specialize"> + <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <!--<ProductKey>6XBNX-4JQGW-QX6QG-74P76-72V67</ProductKey>--> + <ComputerName>vagrant-1903</ComputerName> + </component> + </settings> + <cpi:offlineImage cpi:source="wim:c:/users/jacqueline/desktop/iso%202016/sources/install.wim#Windows Server 2016 Technical Preview 5 SERVERSTANDARDCORE" xmlns:cpi="urn:schemas-microsoft-com:cpi" /> +</unattend> diff --git a/extra/files/gen2-centos/ks.cfg b/extra/files/gen2-centos/ks.cfg index 636ef1f..6b88bb6 100644 --- a/extra/files/gen2-centos/ks.cfg +++ b/extra/files/gen2-centos/ks.cfg @@ -102,6 +102,7 @@ mc curl wget yum-priorities +yum-versionlock yum-utils yum-cron openssh-server diff --git a/extra/files/gen2-centos/prepare_neofetch.sh b/extra/files/gen2-centos/prepare_neofetch.sh index cb2507e..86aa833 100755 --- a/extra/files/gen2-centos/prepare_neofetch.sh +++ b/extra/files/gen2-centos/prepare_neofetch.sh @@ -5,8 +5,8 @@ config="/etc/neofetch/config.conf" config_dir="/etc/neofetch" if [ ! -d $config_dir ];then - echo "No $config_dir exists" - mkdir $config_dir + echo "No $config_dir exists - creating one" + mkdir -v $config_dir fi if [ ! -e $config ];then @@ -17,6 +17,7 @@ if [ ! -e $config ];then fi if [ -e $config ]; then + echo "Starting Neofetch configuration" # comment sed -i -e 's/^[[:blank:]]*info "Packages" packages/#info "Packages" packages/g' $config sed -i -e 's/^[[:blank:]]*info "Resolution" resolution/#info "Resolution" resolution/g' $config @@ -30,6 +31,9 @@ if [ -e $config ]; then # uncomment sed -i -e 's/^[[:blank:]]*# info "Disk" disk/info "Disk" disk/g' $config sed -i -e 's/^[[:blank:]]*# info "Local IP" local_ip/info "Local IP" local_ip/g' $config + # disable color block - workaround for HV console + sed -i -e 's/color_blocks="on"/color_blocks="off"/g' $config + echo "Finished Neofetch configuration" else - echo "File $config doesn't exist" + echo "File $config doesn't exist - couldn't configure neofetch" fi diff --git a/extra/files/gen2-centos/provision.sh b/extra/files/gen2-centos/provision.sh index a3f658d..c65853b 100755 --- a/extra/files/gen2-centos/provision.sh +++ b/extra/files/gen2-centos/provision.sh @@ -1,71 +1,146 @@ #!/bin/bash +INSTALL_UPDATES=true +INSTALL_PUPPET=true +INSTALL_HYPERV=true +INSTALL_WEBMIN=true +STAMP_FILE="/etc/packerinfo" + +usage() { echo "Usage: $0 [-u <true|false> INSTALL_UPDATES ] [-p <true|false> INSTALL_PUPPET] [-w <true|false> INSTALL_WEBMIN] [-h <true|false> INSTALL_HYPERV] " 1>&2; } + +while getopts :u:p:h:w: option + do + case "${option}" + in + u) + INSTALL_UPDATES="${OPTARG}" + ;; + p) + INSTALL_PUPPET="${OPTARG}" + ;; + h) + INSTALL_HYPERV="${OPTARG}" + ;; + w) + INSTALL_WEBMIN="${OPTARG}" + ;; + *) + usage + ;; + esac + done +echo "INSTALL_UPDATES = "$INSTALL_UPDATES +echo "INSTALL_WEBMIN = "$INSTALL_WEBMIN +echo "INSTALL_HYPERV = "$INSTALL_HYPERV +echo "INSTALL_PUPPET = "$INSTALL_PUPPET + # generic - basic repositories and basic stuff -echo "Provisioning phase 1 - EPEL, SELinux and basic packages" +echo "Provisioning phase 1 - Starting: EPEL, SELinux and basic packages" if [ -d /etc/pki/rpm-gpg ]; then rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY* fi - +echo "Provisioning phase 1 - essential packages and EPEL" yum -y makecache fast -yum -y -e 0 install epel-release yum-priorities yum-utils yum-cron yum-plugin-versionlock mc wget curl +yum -y -e 0 install epel-release yum-plugin-priorities yum-utils yum-cron yum-plugin-versionlock mc wget curl yum-config-manager -y -q -e 0 --enable epel --setopt="epel.priority=60"|grep -i "enabled =" -yum -y -e 0 -q update -yum -y -e 0 -q clean all -rm -rf /var/cache/yum + +if [ $INSTALL_UPDATES == "true" ]; then + echo "Provisioning phase 1 - system updates" + yum -y -e 0 -q update + yum -y -e 0 -q clean all + rm -rf /var/cache/yum +else + echo "Provisioning phase 1 - skipping system updates" +fi + # disable selinux +echo "Provisioning phase 1 - disabling SELinux" sed -i /etc/sysconfig/selinux -r -e 's/^SELINUX=.*/SELINUX=disabled/g' sed -i /etc/selinux/config -r -e 's/^SELINUX=.*/SELINUX=disabled/g' +echo "Provisioning phase 1 - all done" +echo "Provisioning phase 2 - Starting: Webmin, Zabbix, Puppet" -echo "Provisioning phase 2 - Webmin, Zabbix, Puppet" # webmin repository -if [ -f /tmp/webmin.repo ]; then - mv /tmp/webmin.repo /etc/yum.repos.d/webmin.repo +if [ $INSTALL_WEBMIN == "true" ]; then + echo "Provisioning phase 2 - Webmin" + if [ -f /tmp/webmin.repo ]; then + mv /tmp/webmin.repo /etc/yum.repos.d/webmin.repo + wget http://www.webmin.com/jcameron-key.asc && rpm --import jcameron-key.asc && rm jcameron-key.asc -f + yum-config-manager -y -q --enable webmin --setopt="webmin.priority=20"|grep -i "enabled =" + yum -y -e 0 makecache fast + yum -y -e 0 install webmin + fi +else + echo "Provisioning phase 2 - skipping Webmin" fi + # zabbix -yum -y -e 0 install https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm +echo "Provisioning phase 2 - Zabbix" +# zabbix 4.2 repository +yum -y -e 0 install https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-release-4.2-2.el7.noarch.rpm yum-config-manager -y -q --disable zabbix-non-supported|grep -i "enabled =" yum-config-manager -y -q --enable zabbix --setopt="zabbix.priority=20"|grep -i "enabled =" yum -y -e 0 makecache fast yum -y -e 0 install zabbix-agent -# webmin -wget http://www.webmin.com/jcameron-key.asc && rpm --import jcameron-key.asc && rm jcameron-key.asc -f -yum-config-manager -y -q --enable webmin --setopt="webmin.priority=20"|grep -i "enabled =" -yum -y -e 0 makecache fast -yum -y -e 0 install webmin - # puppet -yum -y install https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm -yum-config-manager -y -q --enable puppetlabs-products --setopt="puppetlabs-products.priority=10"|grep -i "enabled =" -yum-config-manager -y -q --enable puppetlabs-deps --setopt="puppetlabs-deps.priority=10"|grep -i "enabled =" -yum -y -e 0 install puppet-agent -systemctl stop puppet -systemctl disable puppet -if [ -d /etc/puppetlabs/puppet/ssl ]; then - rm -rf /etc/puppetlabs/puppet/ssl -fi +if [ $INSTALL_PUPPET == "true" ]; then + + echo "Provisioning phase 2 - Puppet Agent" + # puppet 5.x repository + yum -y install https://yum.puppet.com/puppet5-release-el-7.noarch.rpm + yum-config-manager -y -q --enable puppetlabs-products --setopt="puppetlabs-products.priority=10"|grep -i "enabled =" + yum-config-manager -y -q --enable puppetlabs-deps --setopt="puppetlabs-deps.priority=10"|grep -i "enabled =" + yum -y -e 0 install puppet-agent + echo "Provisioning phase 2 - Puppet Agent cleaning" + systemctl stop puppet + systemctl disable puppet + if [ -d /etc/puppetlabs/puppet/ssl ]; then + rm -rf /etc/puppetlabs/puppet/ssl + fi -if [ -f /tmp/puppet.conf ]; then - mv /tmp/puppet.conf /etc/puppetlabs/puppet/puppet.conf + if [ -f /tmp/puppet.conf ]; then + mv /tmp/puppet.conf /etc/puppetlabs/puppet/puppet.conf + fi +else + echo "Provisioning phase 2 - Skipping Puppet agent" fi -echo "Provisioning phase 3 - Extra packages, firewalld, settings" +echo "Provisioning phase 2 - Done" +echo "Provisioning phase 3 - Starting: Extra packages, timezones, neofetch, firewalld, settings" # misc +echo "Provisioning phase 3 - Timezone/Yum Groups" timedatectl set-timezone Europe/Copenhagen --no-ask-password +yum -y groups list yum -y groups mark install "X Window System" # neofetch +echo "Provisioning phase 3 - Nefoetch" curl -o /etc/yum.repos.d/konimex-neofetch.repo https://copr.fedorainfracloud.org/coprs/konimex/neofetch/repo/epel-7/konimex-neofetch-epel-7.repo +echo "Provisioning phase 3 - Extra Packages" yum -y install htop atop iftop iotop firewalld bmon nmap realmd samba nmon samba-common oddjob oddjob-mkhomedir sssd ntpdate ntp adcli krb5-workstation sssd-libwbclient jq firefox gparted pv neofetch screen telnet ncdu tmux +echo "Provisioning phase 3 - MOTD" + if [ -f /tmp/motd.sh ]; then mv /tmp/motd.sh /etc/profile.d/motd.sh chmod +x /etc/profile.d/motd.sh fi -# Hyper-v daemons -yum -y install hyperv-daemons -systemctl enable hypervfcopyd -systemctl enable hypervkvpd -systemctl enable hypervvssd +if [ $INSTALL_HYPERV == "true" ]; then + echo "Provisioning phase 3 - Hyper-V/SCVMM Daemons" + # Hyper-v daemons + yum -y install hyperv-daemons + systemctl enable hypervfcopyd + systemctl enable hypervkvpd + systemctl enable hypervvssd + if [ -e /tmp/install ]; then + cd /tmp + chmod +x /tmp/install + /tmp/install /tmp/scvmmguestagent.1.0.3.1022.x64.tar + fi +else + echo "Provisioning phase 3 - Skipping Hyper-V/SCVMM Daemons" +fi +echo "Provisioning phase 3 - Firewalld" # Firewalld basic configuration. systemctl start firewalld firewall-cmd --permanent --zone=work --add-interface=eth0 @@ -77,21 +152,42 @@ firewall-cmd --permanent --remove-service=ssh --zone=work firewall-cmd --reload # systemd - enable and disable services +echo "Provisioning phase 3 - Services" chkconfig webmin on systemctl enable firewalld systemctl enable ntpd systemctl enable sshd systemctl set-default multi-user.target +echo "Provisioning phase 3 - Services done" echo "Provisioning phase 4 - Final updates and cleaning up" + +if [ $INSTALL_UPDATES == "true" ]; then + echo "Provisioning phase 4 - system final updates" + yum -y -e 0 -q update + yum -y -e 0 -q clean all + rm -rf /var/cache/yum +else + echo "Provisioning phase 4 - skipping system final updates" +fi + # almost done yum -y -e 0 -q clean all -yum -y -e 0 update -package-cleanup --oldkernels --count=2 +package-cleanup --oldkernels --count=2 -y yum -y -e 0 -q clean all rm -rf /var/cache/yum + ## Clean logs truncate -s 0 /var/log/*.* truncate -s 0 /var/log/**/*.* find /var/log -type f -name '*.[0-99].gz' -exec rm {} + rm -rfv /var/log/anaconda/* +cat /etc/centos-release +# Create STAMP_FILE +if [ -e $STAMP_FILE ]; then + rm -rfv $STAMP_FILE + touch $STAMP_FILE +fi +echo "creationDate: "$(date +%Y-%m-%d_%H:%M) >>$STAMP_FILE +echo "Provisioning phase 4 - Done" +echo "Provisioning done - all phases" \ No newline at end of file diff --git a/extra/files/gen2-centos/zeroing.sh b/extra/files/gen2-centos/zeroing.sh index 030e76b..6ad28b6 100644 --- a/extra/files/gen2-centos/zeroing.sh +++ b/extra/files/gen2-centos/zeroing.sh @@ -1,5 +1,6 @@ #!/bin/bash # Zeroing echo "Zeroing phase" -time dd if=/dev/zero|pv -treb|dd of=/file.zero bs=4096;sync;sync;rm -rfv /file.zero;sync;sync + time dd if=/dev/zero|pv -treb|dd of=/file.zero bs=4096;sync;sync;rm -rfv /file.zero;sync;sync + rm -rfv /file.zero||true echo "Zeroing done" diff --git a/extra/scripts/phase-1.ps1 b/extra/scripts/phase-1.ps1 index 7a32972..ab93884 100755 --- a/extra/scripts/phase-1.ps1 +++ b/extra/scripts/phase-1.ps1 @@ -7,27 +7,31 @@ function whichWindows { $version=(Get-WMIObject win32_operatingsystem).name switch -Regex ($version) { '(Server 2016)' { - Write-Output "Server 2016 found" $global:os="2016" + printWindowsVersion } '(Server 2019)' { - Write-Output "Server 2019 found" $global:os="2019" + printWindowsVersion } '(Microsoft Windows Server Standard|Microsoft Windows Server Datacenter)'{ $ws_version=(Get-WmiObject win32_operatingsystem).buildnumber switch -Regex ($ws_version) { '16299' { - Write-Output "Windows Server 1709 found" $global:os="1709" + printWindowsVersion } '17134' { - Write-Output "Windows Server 1803 found" $global:os="1803" + printWindowsVersion } '17763' { - Write-Output "Windows Server 1809 found" $global:os="1809" + printWindowsVersion + } + '18362' { + $global:os="1903" + printWindowsVersion } } } @@ -39,15 +43,23 @@ $version=(Get-WMIObject win32_operatingsystem).name {Write-Output "unknown"} } } +function printWindowsVersion { + if ($global:os) { + Write-Output "Windows Server "$global:os" found." + } + else { + Write-Output "Unknown version of Windows Server found." + } +} whichWindows # Phase 1 - Mandatory generic stuff Write-Output "Start of Phase-1" Import-Module ServerManager -#2016/1709/1803/1809 +#2016/1709/1803/1903/1809 if ($global:os -notlike '2019') { # Install-WindowsFeature NET-Framework-Core,NET-Framework-Features,PowerShell-V2 -IncludeManagementTools } -# 1709/1803/1809/2019 +# 1709/1803/1809/1903/2019 if ($global:os -notlike '2016') { Enable-NetFirewallRule -DisplayGroup "Windows Defender Firewall Remote Management" -Verbose } @@ -71,6 +83,7 @@ try { Enable-NetFirewallRule -DisplayName "File and Printer Sharing (Echo Request - ICMPv4-In)" -Verbose } catch { + Write-Output "Phase 1 - setting firewall went wrong" } # Terminal services and sysprep registry entries @@ -81,6 +94,7 @@ try { Set-ItemProperty -Path 'HKLM:\SYSTEM\Setup\Status\SysprepStatus' -Name 'GeneralizationState' -Value 7 -Verbose -Force } catch { + Write-Output "Phase 1 - setting registry went wrong" } # remove Windows Defender @@ -88,13 +102,14 @@ try { Remove-WindowsFeature -Name Windows-Defender-Features -IncludeManagementTools -ErrorAction SilentlyContinue -Verbose } catch { + Write-Output "Phase 1 - removing Windows Defender went wrong" } # Install chocolatey try { - Set-ExecutionPolicy Bypass; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) + Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) } catch { - Write-Output "Phase 1 choco install problem, exiting" + Write-Output "Phase 1 - choco install problem, exiting" exit (-1) } diff --git a/extra/scripts/phase-2.ps1 b/extra/scripts/phase-2.ps1 index 11b0876..63c7745 100755 --- a/extra/scripts/phase-2.ps1 +++ b/extra/scripts/phase-2.ps1 @@ -1,13 +1,36 @@ # Phase 2 - generic and essential stuff +$goterror=0 + Write-Output "Start of Phase-2" - Set-TimeZone -Id "Central European Standard Time" -Verbose + try { + Set-TimeZone -Id "Central European Standard Time" -Verbose + } + catch { + Write-Output "Phase 2 - set timezone went wrong" + $goterror=1 + } try { Write-Output "Setting high performance power plan" powercfg.exe /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c } catch { + Write-Output "Phase 2 - set powercfg went wrong" + $goterror=1 + } + try { + choco feature enable -n allowEmptyChecksums + choco install conemu sysinternals dotnetfx -y --force + } + catch { + Write-Output "Phase 2 - choco install base packages went wrong" + $goterror=1 + } + + Write-Output "End of Phase-2" + if ($goterror) { + Write-Output "End of Phase-2 something went wrong" + exit (-1) + } + else { + exit 0 } - choco feature enable -n allowEmptyChecksums - choco install conemu sysinternals dotnet4.7.2 -y --force -Write-Output "End of Phase-2" -exit 0 diff --git a/extra/scripts/phase-3.ps1 b/extra/scripts/phase-3.ps1 index f657c2e..8d84e0f 100755 --- a/extra/scripts/phase-3.ps1 +++ b/extra/scripts/phase-3.ps1 @@ -3,7 +3,7 @@ # exit 0 Write-Output "Start of Phase-3" - $puppet_version="5.5.13" + $puppet_version="5.5.16" # add your stuff here # add my myget source try { diff --git a/extra/scripts/phase-5b.docker.ps1 b/extra/scripts/phase-5b.docker.ps1 index 78a6e1f..0ca10de 100644 --- a/extra/scripts/phase-5b.docker.ps1 +++ b/extra/scripts/phase-5b.docker.ps1 @@ -1,5 +1,5 @@ # Enable docker -$requiredVersion="18.09" +$requiredVersion="19.03.1" $installCompose = $true Write-Output "Start Phase 5b-Docker" diff --git a/hv_centos76_g2.cmd b/hv_centos76_g2.cmd index fa9a40b..a57352c 100755 --- a/hv_centos76_g2.cmd +++ b/hv_centos76_g2.cmd @@ -1,3 +1,4 @@ set PACKER_LOG=0 -packer validate .\templates\hv_centos76_g2.json -packer build --force .\templates\hv_centos76_g2.json +packer version +packer validate -var-file=.\variables\variables_centos76.json .\templates\hv_centos7_g2.json +packer build --force -var-file=.\variables\variables_centos76.json .\templates\hv_centos7_g2.json diff --git a/hv_centos76_g2_docker.cmd b/hv_centos76_g2_docker.cmd index 0663983..f7ab6c2 100755 --- a/hv_centos76_g2_docker.cmd +++ b/hv_centos76_g2_docker.cmd @@ -1,3 +1,3 @@ set PACKER_LOG=0 -packer validate .\templates\hv_centos76_g2_docker.json -packer build --force .\templates\hv_centos76_g2_docker.json +packer validate -var-file=.\variables\variables_centos76.json .\templates\hv_centos7_g2_docker.json +packer build --force -var-file=.\variables\variables_centos76.json .\templates\hv_centos7_g2_docker.json \ No newline at end of file diff --git a/hv_centos77_g2.cmd b/hv_centos77_g2.cmd new file mode 100755 index 0000000..2dece5b --- /dev/null +++ b/hv_centos77_g2.cmd @@ -0,0 +1,4 @@ +set PACKER_LOG=0 +packer version +packer validate -var-file=.\variables\variables_centos77.json .\templates\hv_centos7_g2.json +packer build --force -var-file=.\variables\variables_centos77.json .\templates\hv_centos7_g2.json diff --git a/hv_centos77_g2_docker.cmd b/hv_centos77_g2_docker.cmd new file mode 100755 index 0000000..4b1c3d4 --- /dev/null +++ b/hv_centos77_g2_docker.cmd @@ -0,0 +1,5 @@ +set PACKER_LOG=0 +packer validate -var-file=.\variables\variables_centos77.json .\templates\hv_centos7_g2_docker.json +packer build --force -var-file=.\variables\variables_centos77.json .\templates\hv_centos7_g2_docker.json + + diff --git a/hv_centos77_g2_vagrant.cmd b/hv_centos77_g2_vagrant.cmd new file mode 100755 index 0000000..11f7a5c --- /dev/null +++ b/hv_centos77_g2_vagrant.cmd @@ -0,0 +1,4 @@ +set PACKER_LOG=0 +packer version +packer validate -var-file=.\variables\variables_centos77.json .\templates\hv_centos7_g2_vagrant.json +packer build --force -var-file=.\variables\variables_centos77.json .\templates\hv_centos7_g2_vagrant.json diff --git a/templates/hv_centos76_g2_vagrant.json b/templates/hv_centos7_g2.json similarity index 70% rename from templates/hv_centos76_g2_vagrant.json rename to templates/hv_centos7_g2.json index ceaf5ec..9f046dc 100755 --- a/templates/hv_centos76_g2_vagrant.json +++ b/templates/hv_centos7_g2.json @@ -11,7 +11,7 @@ "disk_block_size": "1", "communicator": "ssh", "ssh_username": "root", - "ssh_password": "password", + "ssh_password": "{{ user `ssh_password` }}", "ssh_timeout" : "4h", "shutdown_timeout": "30m", "shutdown_command": "echo 'password' | sudo -S shutdown -P now", @@ -62,11 +62,6 @@ "source": "extra/files/gen2-centos/zeroing.sh", "destination": "/tmp/zeroing.sh" }, - { - "type": "file", - "source": "extra/files/gen2-centos/vagrant.sh", - "destination": "/tmp/vagrant.sh" - }, { "type": "file", "source": "extra/files/gen2-centos/uefi.sh", @@ -82,44 +77,24 @@ "source": "extra/files/gen2-centos/scagent/1.0.3.1022/install", "destination": "/tmp/install" }, - { - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", - "inline": [ - "chmod +x /tmp/install", - "cd /tmp", - "/tmp/install /tmp/scvmmguestagent.1.0.3.1022.x64.tar" - ], - "inline_shebang": "/bin/sh -x", - "type": "shell" - }, { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ "chmod +x /tmp/provision.sh", - "/tmp/provision.sh", + "/tmp/provision.sh {{ user `provision_script_options` }}", "reboot" ], "inline_shebang": "/bin/sh -x", "type": "shell", "expect_disconnect": true }, - { - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", - "inline": [ - "chmod +x /tmp/prepare_neofetch.sh", - "chmod +x /tmp/vagrant.sh", - "/tmp/prepare_neofetch.sh", - "/tmp/vagrant.sh", - "chmod +x /usr/local/bin/uefi.sh" - ], - "inline_shebang": "/bin/sh -x", - "type": "shell" - }, { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ "echo Last Phase", - "yum -y -e 0 update", + "chmod +x /usr/local/bin/uefi.sh", + "chmod +x /tmp/prepare_neofetch.sh", + "/tmp/prepare_neofetch.sh", "systemctl set-default multi-user.target", "systemctl disable initial-setup-text", "systemctl disable initial-setup-graphical", @@ -128,31 +103,24 @@ "/bin/rm -f /etc/ssh/*key*", "chmod +x /tmp/zeroing.sh", "/tmp/zeroing.sh", - "/bin/rm -rfv /tmp/*" + "/bin/rm -rfv /tmp/*", + "echo 'packerVersion: {{ packer_version }}' >>/etc/packerinfo" ], "inline_shebang": "/bin/sh -x", "type": "shell", "pause_before": "60s" } ], - "post-processors": [ - { - "type": "vagrant", - "keep_input_artifact": true, - "output": "{{ user `output_vagrant` }}", - "vagrantfile_template": "{{ user `vagrantfile_template` }}" - } - ], "variables": { - "iso_url": "http://mirror-pl.kielcetechnologypark.net/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1810.iso", - "iso_checksum_type": "sha256", - "iso_checksum": "918975cdf947e858c9a0c77d6b90a9a56d9977f3a4496a56437f46f46200cf71", + "iso_url": "", + "iso_checksum_type": "none", + "iso_checksum": "", "switch_name": "", - "vm_name": "packer-centos76-g2", + "vm_name": "", "disk_size": "70000", "vlan_id": "", - "output_directory": "output-centos76", - "output_vagrant": "./vbox/packer-centos-76-g2.box", - "vagrantfile_template": "./vagrant/hv_centos76_g2.template" + "output_directory": "", + "ssh_password": "", + "provision_script_options": "" } } \ No newline at end of file diff --git a/templates/hv_centos76_g2_docker.json b/templates/hv_centos7_g2_docker.json similarity index 80% rename from templates/hv_centos76_g2_docker.json rename to templates/hv_centos7_g2_docker.json index 8912229..f88b7f1 100755 --- a/templates/hv_centos76_g2_docker.json +++ b/templates/hv_centos7_g2_docker.json @@ -2,7 +2,7 @@ "builders": [ { "type": "hyperv-iso", - "vm_name": "{{ user `vm_name` }}", + "vm_name": "{{ user `vm_name` }}-dck", "temp_path": ".", "iso_url": "{{ user `iso_url` }}", "iso_checksum_type": "{{user `iso_checksum_type`}}", @@ -12,7 +12,7 @@ "disk_block_size": "1", "communicator": "ssh", "ssh_username": "root", - "ssh_password": "password", + "ssh_password": "{{ user `ssh_password` }}", "ssh_timeout" : "4h", "shutdown_timeout": "30m", "shutdown_command": "echo 'password' | sudo -S shutdown -P now", @@ -29,7 +29,7 @@ ], "guest_additions_mode":"disable", "enable_secure_boot": false, - "output_directory": "{{ user `output_directory` }}" + "output_directory": "{{ user `output_directory` }}-dck" } ], "provisioners": [ @@ -83,21 +83,11 @@ "source": "extra/files/gen2-centos/scagent/1.0.3.1022/install", "destination": "/tmp/install" }, - { - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", - "inline": [ - "chmod +x /tmp/install", - "cd /tmp", - "/tmp/install /tmp/scvmmguestagent.1.0.3.1022.x64.tar" - ], - "inline_shebang": "/bin/sh -x", - "type": "shell" - }, { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ "chmod +x /tmp/provision.sh", - "/tmp/provision.sh", + "/tmp/provision.sh {{ user `provision_script_options` }}", "reboot" ], "inline_shebang": "/bin/sh -x", @@ -107,13 +97,10 @@ { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ - "chmod +x /tmp/prepare_neofetch.sh", - "/tmp/prepare_neofetch.sh", - "chmod +x /usr/local/bin/uefi.sh", "chmod +x /tmp/mkfs_device.sh", "/tmp/mkfs_device.sh /dev/sdb", "mkdir -p /var/lib/docker", - "aa=`blkid |grep /dev/sdb1| awk '{print $2}'`;echo $aa' /var/lib/docker ext4 defaults 1 1' >>/etc/fstab", + "docker=`blkid |grep /dev/sdb1| awk '{print $2}'`;echo $docker' /var/lib/docker ext4 defaults 1 1' >>/etc/fstab", "mount -a", "df -h" ], @@ -124,7 +111,9 @@ "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ "echo Last Phase", - "yum -y -e 0 update", + "chmod +x /usr/local/bin/uefi.sh", + "chmod +x /tmp/prepare_neofetch.sh", + "/tmp/prepare_neofetch.sh", "systemctl set-default multi-user.target", "systemctl disable initial-setup-text", "systemctl disable initial-setup-graphical", @@ -133,7 +122,8 @@ "/bin/rm -f /etc/ssh/*key*", "chmod +x /tmp/zeroing.sh", "/tmp/zeroing.sh", - "/bin/rm -rfv /tmp/*" + "/bin/rm -rfv /tmp/*", + "echo 'packerVersion: {{ packer_version }}' >>/etc/packerinfo" ], "inline_shebang": "/bin/sh -x", "type": "shell", @@ -141,14 +131,16 @@ } ], "variables": { - "iso_url": "http://mirror-pl.kielcetechnologypark.net/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1810.iso", - "iso_checksum_type": "sha256", - "iso_checksum": "918975cdf947e858c9a0c77d6b90a9a56d9977f3a4496a56437f46f46200cf71", + "iso_url": "", + "iso_checksum_type": "none", + "iso_checksum": "", "switch_name": "", - "vm_name": "packer-centos76-g2-dck", + "vm_name": "", "disk_size": "70000", "disk_additional_size":"150000", "vlan_id": "", - "output_directory": "output-centos76-dck" + "output_directory": "", + "ssh_password": "", + "provision_script_options": "" } } \ No newline at end of file diff --git a/templates/hv_centos76_g2.json b/templates/hv_centos7_g2_vagrant.json similarity index 78% rename from templates/hv_centos76_g2.json rename to templates/hv_centos7_g2_vagrant.json index 93fa65e..1634284 100755 --- a/templates/hv_centos76_g2.json +++ b/templates/hv_centos7_g2_vagrant.json @@ -11,7 +11,7 @@ "disk_block_size": "1", "communicator": "ssh", "ssh_username": "root", - "ssh_password": "password", + "ssh_password": "{{ user `ssh_password` }}", "ssh_timeout" : "4h", "shutdown_timeout": "30m", "shutdown_command": "echo 'password' | sudo -S shutdown -P now", @@ -62,6 +62,11 @@ "source": "extra/files/gen2-centos/zeroing.sh", "destination": "/tmp/zeroing.sh" }, + { + "type": "file", + "source": "extra/files/gen2-centos/vagrant.sh", + "destination": "/tmp/vagrant.sh" + }, { "type": "file", "source": "extra/files/gen2-centos/uefi.sh", @@ -77,42 +82,26 @@ "source": "extra/files/gen2-centos/scagent/1.0.3.1022/install", "destination": "/tmp/install" }, - { - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", - "inline": [ - "chmod +x /tmp/install", - "cd /tmp", - "/tmp/install /tmp/scvmmguestagent.1.0.3.1022.x64.tar" - ], - "inline_shebang": "/bin/sh -x", - "type": "shell" - }, { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ "chmod +x /tmp/provision.sh", - "/tmp/provision.sh", + "/tmp/provision.sh {{ user `provision_script_options` }}", "reboot" ], "inline_shebang": "/bin/sh -x", "type": "shell", "expect_disconnect": true }, - { - "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", - "inline": [ - "chmod +x /tmp/prepare_neofetch.sh", - "/tmp/prepare_neofetch.sh", - "chmod +x /usr/local/bin/uefi.sh" - ], - "inline_shebang": "/bin/sh -x", - "type": "shell" - }, { "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'", "inline": [ "echo Last Phase", - "yum -y -e 0 update", + "chmod +x /usr/local/bin/uefi.sh", + "chmod +x /tmp/prepare_neofetch.sh", + "chmod +x /tmp/vagrant.sh", + "/tmp/prepare_neofetch.sh", + "/tmp/vagrant.sh", "systemctl set-default multi-user.target", "systemctl disable initial-setup-text", "systemctl disable initial-setup-graphical", @@ -121,21 +110,34 @@ "/bin/rm -f /etc/ssh/*key*", "chmod +x /tmp/zeroing.sh", "/tmp/zeroing.sh", - "/bin/rm -rfv /tmp/*" + "/bin/rm -rfv /tmp/*", + "echo 'packerVersion: {{ packer_version }}' >>/etc/packerinfo" ], "inline_shebang": "/bin/sh -x", "type": "shell", "pause_before": "60s" } ], + "post-processors": [ + { + "type": "vagrant", + "keep_input_artifact": true, + "output": "{{ user `output_vagrant` }}", + "vagrantfile_template": "{{ user `vagrantfile_template` }}" + } + ], "variables": { - "iso_url": "http://mirror-pl.kielcetechnologypark.net/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1810.iso", - "iso_checksum_type": "sha256", - "iso_checksum": "918975cdf947e858c9a0c77d6b90a9a56d9977f3a4496a56437f46f46200cf71", + "iso_url": "", + "iso_checksum_type": "", + "iso_checksum": "", "switch_name": "", - "vm_name": "packer-centos76-g2", + "vm_name": "", "disk_size": "70000", "vlan_id": "", - "output_directory": "output-centos76" + "output_directory": "", + "ssh_password": "", + "output_vagrant": "./vbox/packer-centos-77-g2.box", + "vagrantfile_template": "./vagrant/hv_centos77_g2.template", + "provision_script_options": "" } } \ No newline at end of file diff --git a/vagrant/hv_centos77_g2.template b/vagrant/hv_centos77_g2.template new file mode 100644 index 0000000..5549efd --- /dev/null +++ b/vagrant/hv_centos77_g2.template @@ -0,0 +1,27 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.require_version ">= 1.6.2" + +Vagrant.configure("2") do |config| + config.vm.define "vagrant-centos77" + config.vm.box = "centos77" + config.vm.communicator = "ssh" + config.vm.synced_folder ".", "/vagrant", type: "rsync", disabled: "true" + + # Admin user name and password + config.ssh.username = "vagrant" + config.ssh.password = "vagrant" + config.vm.guest = :redhat + +# config.vm.provider "hyperv" do |h| +# h.vm_integration_services = { +# guest_service_interface: true, +# heartbeat: true, +# key_value_pair_exchange: true, +# shutdown: true, +# time_synchronization: true, +# vss: boolean +# } +# end + end diff --git a/vagrant_hv_centos76_g2.cmd b/vagrant_hv_centos76_g2.cmd deleted file mode 100755 index a305938..0000000 --- a/vagrant_hv_centos76_g2.cmd +++ /dev/null @@ -1,3 +0,0 @@ -set PACKER_LOG=0 -packer validate .\templates\hv_centos76_g2_vagrant.json -packer build -var "switch_name=Default" .\templates\hv_centos76_g2_vagrant.json diff --git a/validate_all.sh b/validate_all.sh deleted file mode 100755 index 2fd79bf..0000000 --- a/validate_all.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -echo "validating ./templates/hv_centos75_g2.json" -packer validate ./templates/hv_centos75_g2.json -echo "validating ./templates/hv_win2016_g1.json" -packer validate ./templates/hv_win2016_g1.json -echo "validating ./templates/hv_win2016_g2.json" -packer validate ./templates/hv_win2016_g2.json -echo "validating ./templates/hv_win2016_1709_g2.json" -packer validate ./templates/hv_win2016_1709_g2.json -echo "validating ./templates/hv_win2016_1803_g2.json" -packer validate ./templates/hv_win2016_1803_g2.json diff --git a/variables/variables_centos76.json b/variables/variables_centos76.json new file mode 100644 index 0000000..4ccd4d3 --- /dev/null +++ b/variables/variables_centos76.json @@ -0,0 +1,15 @@ +{ + "iso_url": "http://mirror-pl.kielcetechnologypark.net/centos/7/isos/x86_64/CentOS-7-x86_64-Everything-1810.iso", + "iso_checksum_type": "sha256", + "iso_checksum": "918975cdf947e858c9a0c77d6b90a9a56d9977f3a4496a56437f46f46200cf71", + "vm_name": "packer-centos76-g2", + "disk_size": "70000", + "disk_additional_size":"150000", + "switch_name": "vSwitch", + "output_directory": "output-centos76", + "output_vagrant": "./vbox/packer-centos-76-g2.box", + "vlan_id": "", + "vagrantfile_template": "./vagrant/hv_centos76_g2.template", + "ssh_password": "password", + "provision_script_options": "-u false -p true -h true -w true" + } \ No newline at end of file diff --git a/variables/variables_centos77.json b/variables/variables_centos77.json new file mode 100644 index 0000000..b4d8ddb --- /dev/null +++ b/variables/variables_centos77.json @@ -0,0 +1,15 @@ +{ + "iso_url": "http://ftp.ps.pl/pub/Linux/CentOS/7.7.1908/isos/x86_64/CentOS-7-x86_64-Everything-1908.iso", + "iso_checksum_type": "sha256", + "iso_checksum": "bd5e6ca18386e8a8e0b5a9e906297b5610095e375e4d02342f07f32022b13acf", + "vm_name": "packer-centos77-g2", + "disk_size": "70000", + "disk_additional_size":"150000", + "switch_name": "vSwitch", + "output_directory": "output-centos77", + "output_vagrant": "./vbox/packer-centos-77-g2.box", + "vlan_id": "", + "vagrantfile_template": "./vagrant/hv_centos77_g2.template", + "ssh_password": "password", + "provision_script_options": "" + } \ No newline at end of file