Skip to content

Commit

Permalink
updating to HashiCorp Packer
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttyso committed Nov 18, 2023
1 parent c2e59fb commit aeedb48
Show file tree
Hide file tree
Showing 20 changed files with 314 additions and 175 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**/terraform.tfvars
**/.terraform.lock.hcl
**/http/user-data
**/variables.yaml

# Local Python Directories
**/Testing*/*
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
imm-toolkit
intersight-toolkit
Copyright (c) 2023 Cisco Systems, Inc. and/or its affiliates
This project includes software developed at Cisco Systems, Inc. and/or its affiliates.
193 changes: 41 additions & 152 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,194 +1,83 @@
# IMM Toolkit Setup Instructions
# Intersight Toolkit Setup Instructions

## Updates/News

05-04-2023
* Initial Release

## Setup NGINX

Install NGINX and NetTools

```bash
sudo apt install net-tools
```

```bash
sudo apt install nginx
```

Configure Security Settings for nginx.

```bash
sudo vim /etc/nginx/nginx.conf
```

* Copy the contents of the nginx.conf file

Generate the Certificate and Private Key

```bash
cd /etc/nginx
sudo mkdir ssl
cd ssl
sudo openssl req -new -newkey rsa:2048 -days 1095 -nodes -x509 -keyout nginx.key -out nginx.crt
```


```bash
sudo chown www-data:www-data nginx.key
sudo chown www-data:www-data nginx.crt
sudo chmod 400 nginx.crt
sudo chmod 400 nginx.key
```

Setup default site for File Services over HTTPS

```bash
cd /var/www/
sudo mkdir upload
cd upload/
sudo touch test.txt
cd /etc/nginx/sites-enabled
sudo vim default
```

* Copy the contents of nginx-sites-default into the above file

```bash
sudo systemctl restart nginx
sudo systemctl status nginx.service
netstat -tulpn
```

## Setup NTP

* Install NTP

```bash
sudo apt install ntp
```

## Setup OVF Customization Script

```bash
sudo vim /usr/local/bin/ovf_network_config.sh
```
The purpose of this packer example is to build an automation platform to manage Cisco Intersight. The current example deployes a template in a VMware environment, which then can be used to create an OVA for distribution.

* Copy the contents of ovf_network_config.sh
## Updates/News

```bash
sudo vim /etc/systemd/system/ovf-network-config.service
```
* 2023-11-18 - v2.0 - Moving to HashiCorp Packer - Guidance from https://tekanaid.com/posts/hashicorp-packer-build-ubuntu22-04-vmware
* 2023-05-04 - Initial Release

* Copy the contents of ovf-network-config.service
## Setup Environment

* Change the Permissions on the Files
Install the following packages for Packer.

```bash
sudo chmod 744 /usr/local/bin/ovf_network_config.sh
sudo chmod 664 /etc/systemd/system/ovf-network-config.service
sudo systemctl daemon-reload
sudo systemctl enable ovf-network-config.service
```sh
sudo apt install mkisofs whois -y
```

## Install Python and Modules
## Install Packer

```bash
sudo apt install python3-pip
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update -y
sudo apt-get install packer -y
```

```bash
cd ~
mkdir Downloads
chown imm-toolkit:imm-toolkit Downloads
mkdir Logs
chwon imm-toolkit:imm-toolkit Logs
mkdir github
chown imm-toolkit:imm-toolkit github
cd github/
git clone https://github.com/scotttyso/intersight_iac
```
## Generate a hashed password for the user-data file

```bash
sudo ln -s /home/imm-toolkit/github/intersight_iac/ezimm.py /usr/bin/ezimm.py
sudo ln -s /home/imm-toolkit/github/intersight_iac/ezci.py /usr/bin/ezci.py
sudo ln -s /home/imm-toolkit/github/intersight_iac/ezvcenter.ps1 /usr/bin/ezvcenter.ps1
cd intersight_iac/
sudo pip install -r requirements.txt
```
Run the command below and when prompted for PASSWORD enter the Password desired for the User Account.

```bash
cd ~
sudo pip install intersight
mkpasswd -m sha-512 --rounds=4096
```

## Install Ansible and Galaxy Modules

```bash
sudo apt install ansible -y
```
You will get an encrypted password similar to the following:

```bash
ansible-galaxy collection install cisco.intersight
Password: $6$KU2P9m78xF3n$noEN/CV.0R4qMLdDh/TloUplmJ0DLnqi6/cP7hHgfwUu.D0hMaD2sAfxDT3eHP5BQ3HdgDkKuIk8zBh0mDLzO1
```

## Install PowerShell and Modules
* Copy the user-data.example to user-data

```bash
sudo snap install powershell
cd vmware/http/
cp user-data.example user-data
cd ../
```

```bash
pwsh -Command Install-Module -Name Intersight.PowerShell -Force
```
* Update the hostname, username, password (with the hashed password),
* Uncomment the authorized-keys if you would like to add a valid ssh-rsa public key for cloud deployments.
* Copy the variables.yaml.example to variables.yaml

```bash
pwsh -Command Install-Module -Name VMware.PowerCLI -Force
cp variables.yaml.example to variables.yaml
```

* Use the defaults.yaml as an example source and make any modifications you would like to the deployment settings in variables.yaml.

## Install Terraform
## Setup Packer Sensitive Variables

```bash
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list
export PKR_VAR_virtual_machine_password="same_password_as_mkpasswd_plain_text"
export PKR_VAR_vsphere_password="vcenter_password_plain_text"
```

```bash
sudo apt update
```
## Running packer build with hcl

```bash
sudo apt-get install terraform
```sh
packer build -force -on-error=ask vmware.pkr.hcl
```

```bash
terraform -install-autocomplete
```
## Troubleshooting

## Install isdk

```bash
LOCATION=$(curl -s https://api.github.com/repos/cgascoig/isctl/releases/latest \
| grep "tag_name" \
| awk '{print "https://github.com/cgascoig/isctl/releases/download/" substr($2, 2, length($2)-3) \
"/isctl_" substr($2, 2, length($2)-3) "_Linux_x86_64.tar.gz"}' \
| sed 's/isctl_v/isctl_/'); curl -L -o isctl.tar.gz $LOCATION
```

```bash
tar -xvf isctl.tar.gz
rm isctl.tar.gz
sudo mv isctl /usr/local/bin/
sudo chmod +x /usr/local/bin/isctl
```
- If packer gets stuck on `Waiting for IP` you may want to check your DHCP server.

## Setup OVF Customization on VM
## Setup OVF Customization on Virtual Machine

![alt text](vApp-Options.png "vApp Options")

Expand Down
Loading

0 comments on commit aeedb48

Please sign in to comment.