Create a server image with Packer

Packer is a free, open-source application from Hashicorp. It can generate a server image based on an existing one, and configure it for your special needs. You can use the generated image when you launch a server instance in the cloud or on your local workstation.

Install Packer

Packer script

Packer reads a .json file to generate the new server image.

AMI ID

To find the latest AMI IDs log into the Amazon AWS Console, select EC2 and click the Launch button. On the left side click Quick Start to see the images for

  • Amazon Linux
  • SUSE Linux
  • Red Hat Enterprise Linux
  • Ubuntu Server
  • Microsoft Windows Server

For CentOS images, see the “Official CentOS Linux : Public Images” section at  https://wiki.centos.org/Cloud/AWS The AMI IDs are organized by region.

Username

It is important to use the correct ssh_username for each operating system:

Linux

RHEL: ec2-user
Amazon Linux: ec2-user
CentOS: centos
Ubuntu: ubuntu

Windows

any “winrm_username” and “winrm_password”

The PowerShell script in the user data file, specified in the “user_data_file” attribute, sets the initial username and password with the

cmd.exe /c net user /add ...

command.

The Administrator password is set with the

cmd.exe /c net user Administrator ...

command.

IMPORTANT!!!

For Packer to be able to connect to the server, set the same username and password in the  “winrm_username” and “winrm_password”, “elevated_user”, and “elevated_password” attributes of the .json file.

AMI Name

To allow the Chef Kitchen EC2 driver to read the OS version of the image, include the version in the “Name” as follows.

The Test Kitchen Git repository has the following at https://github.com/test-kitchen/kitchen-ec2

Note that the image_search method requires that the AMI image names be in a specific format. Some examples are:

  • Windows-2012
  • Windows-2012r2
  • Windows-2012r2sp1
  • RHEL-7.2

It is safest to use the same naming convention as used by the public images published by the OS vendors on the AWS marketplace.

Sample acceptable names are

  • my_windows-2012r2_base-01
  • my_amzn-ami-hvm_base-01

To find the name of the AMI

  1. In the AWS Console select EC2, and click the Launch Instance button
  2. On the left side select Quick Start, and find the AMI ID of the image you want to start with.
  3. Navigate back to the EC2 console, select AMIs, in the drop-down select Public images
  4. Search for the AMI by ID
  5. Make sure you copy the name of the AMI with the same ID.

 

Generate the server image with Packer

  1. Open a Bash window,
  2. Navigate to the folder of the Packer JSON script,
  3. Execute the following command. Packer will read the default AWS credentials from  ~/.aws/credentials file on your Macintosh or Linux workstation. On Windows, the file is at C:\Users\YOUR_USER_NAME\.aws\credentials.
    packer build MY_PACKER_SCRIPT.json
    1. To specify the AWS keys in the command line
      packer build -var 'aws_access_key=<access key>' -var 'aws_secret_key=<secret key>' MY_PACKER_SCRIPT.json
  4. The command window will display the ID of the generated image, or you can find it by name in the EC2 section of the AWS console under AMIs.

Share the generated server image with other cloud accounts

If you work in multiple cloud accounts you need to share the generated server image with other accounts

AWS

  1. Log into the AWS account you have used to generate the server image,
  2. On the left side of the EC2 section select AMI and find the new image by name of ID,
  3. On the Permissions tab click the Edit button,
  4. Make sure the Private radio button is selected if you don’t want to share the image publicly,
  5. Enter the account number of the account you want to share the image with (see Find the AWS account number),
  6. Check the Add “create volume” permissions… checkbox,
  7. Click the Add Permission button,
  8. When you have added all accounts to share with, click the Save button.

 

Convert PEM files to PPK to use them in PuTTY

When you create a key in AWS you can download it one time in PEM format. To use it in PuTTY, the free SSH and Telnet client, you have to convert it to PPK format.

To install PuTTY, see the Terminal Emulator section in Recommended utilities for your workstation

To convert a PEM file to PPK

  1. Open a terminal window in the folder of the PEM file
  2. Execute the following
    puttygen MYKEY.pem -o MYKEY.ppk

 

Modify STL 3D printing files with FreeCAD

There are many free STL files are available on the internet to 3D print useful objects at home. There are times when we want to make some adjustments to them to better fit our need or 3D printing equipment. If the STL file describes an object that is larger than the maximum dimensions your printer can produce, you can print the object in two or more pieces and glue them together. There are glues on the market that can make as strong bonds as the materials themselves they are attaching together.

There are free applications that can open and edit STL files, one of them is the open source FreeCAD.

Download FreeCAD from https://www.freecadweb.org/wiki/Download

Open and edit STL files in FreeCAD

Import an STL file into FreeCAD

  1. Start FreeCAD and create a new document with File > New,
  2. In the menu select File > Import and navigate to the mesh file you want to modify. FreeCAD can open STL, OBJ, and AST mesh files.
  3. In the dropdown select the Part workbench,
  4. In the Model window select the imported mesh,
  5. In the menu select Part > Create shape from mesh
  6. The default 0.10 tolerance is usually fine for most of the objects we 3D print, click OK,
  7. Delete the imported mesh in the Model window. Right-click the name of the imported mesh and select Delete,
  8. Convert the shapes to solid. In the toolbar click the Advanced Utilities icon,
  9. In the Tasks window select Solid from shell
  10. Click one triangle on the object,
  11. Click the Create button. You will not notice any change because the solid overlaps the shape.
  12. Click the Close button in the Tasks window,
  13. Delete the shape. In the Model window right-click the name of the shape and select Delete. We have converted the mesh to solid, ready to be edited.

Edit the solid model in FreeCAD

  1. To add or remove parts, open the Part Design workbench,
  2. Select the Solid in the Model window, so the object turns green,
  3. In the Part Design menu select Create Sketch
  4. Select the plane you want to draw and click OK,
  5. Draw lines, circles, rectangles that we will extrude to add or subtract them from the object. Don’t worry if the sketch is not at the correct elevation, we will move the sketch to the correct elevation later.
  6. To print a portion of a too large object, draw lines and trim them at the location where you want to separate the object into multiple parts.
  7. To close and save the sketch click the Close Sketch icon in the tool bar.
  8. To continue to edit the sketch, double click it in the Model window.

To change the elevation of a sketch

  1. Select a face on the solid the move the sketch to,
  2. In the Part Design menu select Map sketch to face
  3. Select the sketch in the drop-down list and click OK,
  4. The sketch opens. You can continue the editing of it, or just close it.

 

 

Pause 3D Printing

There are some designs where you want to change the filament or insert a nut into the product. To pause the 3D printing process

  1. Export the design into a .gcode file,
  2. Open the. gcode file with a text editor,
  3. Insert the following lines into the file at the point you want to pause.
    ; Display a message
    M117 Change the filament and continue
    ; Pause the printing
    M600

If you want to print text, it is possible to pause the printing, change the filament to a different color, and continue.

To find the layer where you need to change the color in Cura, the free 3D print utility

  1. Load the STL file of the design into Cura,
  2. Click the View Mode icon in the upper right corner of the screen, and select Layers,
  3. Use the slier to navigate between the layers,
  4. Find the layer that prints the bottom of the groove, and write down the layer number. Note that the slider starts to number the layers with 1.
  5. Save the .gcode file to the disk with the Floppy icon on the left side. If the icon is gray, the design is larger than the printable size of the printer. You may scale the design down with the Scale icon.
  6. Open the .gcode file with a text editor,
  7. Note that the .gcode file starts to number the layers with 0. To stop at the correct layer, we need to subtract 1 from the number we have seen on the slider.
  8. We will change filament colors to print the bottom layer of the groove. In our example, layer 113-1 = 112 printed the bottom of the groove, search for the text Layer:112 in the file,
  9. Place a pause instruction before that line in the file
    ; Display a message
    M117 Change the filament and continue
    ; Pause the printing
    M600
    ;LAYER:112
  10. Find the next layer in the file, in our example, search for the text Layer:113 in the file,
  11. Place another pause instruction before that line in the file to change the color again.
    ; Display a message
    M117 Change the filament and continue
    ; Pause the printing
    M600
    ;LAYER:113
  12. Save the file and start the printing process.

Chef Attributes

Chef attributes are global variables that are available for every cookbook on the node. There are multiple formats to declare and use an attribute. For important notes on the syntax, please see Undefined method or attribute error in a Chef recipe.

To override the value of an attribute that is defined in another cookbook, use the following syntax

node.override['ATTRIBUTE_NAME'] = 'NEW_VALUE'

During compilation, this line will replace the default value of the attribute with the NEW_VALUE.

 

Prevent the auto-termination of stranded instances in RighScale

When you launch an instance with RightScale Self Service, and the Chef cookbook execution fails, the instance goes into “stranded” mode. By default RightScale Self Service terminates the stranded instances, so there is no way to remote into them and read log files to find the cause of the problem.

To keep stranded instances running in RightScale

  1. Find the booting instance in Cloud Management and click the instance name,
  2. Click the lock icon on the top of the screen

RightScale Self Service cannot terminate locked instances. To terminate the instance after the troubleshooting process, unlock the instance and terminate the instance by hand.

Getting started with InSpec

InSpec is an open-source testing framework to verify your infrastructure satisfies the design requirements.

In this article, we will learn to install and use InSpec with Chef.

Install InSpec

  1. Navigate to https://downloads.chef.io/inspec, and download the installer for the operating system of your workstation,
  2. Execute the downloaded installer.

Allow InSpec to verify Red Hat Enterprise Linux instances

InSpec needs “sudo” access to execute the tests, but Red Hat Enterprise Linux prevents that access. Execute the following code on every instance when it runs in Test Kitchen:

if (node.chef_environment == "_default")
  # Running in Test Kitchen

  # Ensure sudo is installed
  package 'Install sudo' do
    package_name 'sudo'
    action :install
  end

  file '/etc/sudoers' do
    mode 0440
    owner 'root'
    group 'root'
    action :create
  end

  delete_lines 'remove hash-comments from /some/file' do
    path '/etc/sudoers'
    pattern '^.*requiretty'
  end

end

 

Start to use InSpec

To use InSpec as the default integration testing tool in Chef Test Kitchen

  1. Open the .kitchen.yml file of the cookbook,
  2. Delete the following lines from the platform section if exist:
    busser:
      sudo: true
  3. Add the following lines to the file between provisioner: and platforms:
    verifier:
      name: inspec
  4. Place the test files into the default location of the InSpec integration test. The “verify” command executes all files in the directory.
    test
    |--smoke
       |--default
          |--MY_RECIPE_NAME1_test.rb
          |--MY_RECIPE_NAME2_test.rb
    
  5. To execute the test file with the verify command, add these lines to every suite. This will execute all test files in the default folder.
        verifier:
          inspec_tests:
            - test/smoke/default
  6. To execute only one test file, specify the file name:
        verifier:
          inspec_tests:
            - test/smoke/default/MY_RECIPE_test.rb
  7. To execute the test file of another suite, use relative path, you can use tests from other cookbooks (../ANOTHER_COOKBOOK/test/recipes/ANOTHER_SUITE_NAME).
        verifier:
          inspec_tests:
            - ../ANOTHER_COOKBOOK/test/smoke/default
  8. Create an integration test for your recipe. Create a new file in the test/recipes/THE_SUITE_NAME folder. The name does not matter, if you are planning to create only one test file for the suite, name the file after the suite: default_test.rb,
  9. The following is a simple example of an InSpec integration test:
    # # encoding: utf-8
    
    # Inspec test for recipe my_cookbook::default
    
    # The Inspec reference, with examples and extensive documentation, can be
    # found at https://docs.chef.io/inspec_reference.html
    
    unless os.windows?
     describe user('root') do
     it { should exist }
     skip 'This is an example test, replace with your own test.'
     end
    end
    
    describe port(80) do
     it { should_not be_listening }
     skip 'This is an example test, replace with your own test.'
    end

As you can see, the syntax of InSpec is (intentionally) very similar to ServerSpec, that it replaces. It is very easy to convert existing ServerSpec integration tests to InSpec compliance tests.

Differences between ServerSpec and InSpec

ServerSpec “process”

Does not work on a Windows host.

On Linux the syntax changed from

 describe process('PROCESS_NAME') do
   it { should be_running }
 end

to

describe processes('PROCESS_NAME') do
  its('states') { should eq ['R<'] }
end

registry_key

The :dword comparison uses the decimal value with no quotes instead of the hex value with quotes

changed from

describe registry_key('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full') do
  it { should have_property_value('Release', :dword, '70805') } # 460805 decimal
end

to

describe registry_key('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full') do
  it { should have_property_value('Release', :dword, 460805) } # For dword use the decimal value, no quotes
end

 

 

For more information

For more information on the Kitchen InSpec verifier visit https://github.com/chef/kitchen-inspec

Import STL mesh files into Autodesk Inventor

Import and export STL mesh files

To enable Autodesk Inventor to open and save .stl files add the STL Import and STL Export add-ins to Adobe Inventor. .stl files are used to transfer 3D print designs between computers. You can download most of them for free from the Internet.

  1. In the Tools menu open the Add-in Manager
  2. On the Translators tab select the STL Import and STL Export translators.

To be able to edit the STL mesh files

install the Mesh Enabler add-in

Download the Autodesk Inventor Mesh Enabler

  1. Navigate to the Autodesk app store at https://apps.autodesk.com/en
  2. Sign in with your Autodesk account
  3. Search for Mesh Enabler
  4. Click the Download button

Install the Autodesk Inventor Mesh Enabler

  1. Double click the downloaded AutodeskMeshEnabler.msi file and complete the installation
  2. Start Autodesk Inventor
  3. In the Tools menu select the Add-in Manager
  4. On the Applications tab select Autodesk Mesh Enabler
  5. Select the Load Automatically checkbox
  6. Click OK

To convert an STL mesh file to a solid model

  1. Start Autodesk Inventor
  2. Open the STL mesh file
  3. In the browser right-click the MeshFeature1 element and select Convert to Base Feature
  4. In the dialog box select the output you need and click OK.

    1. Solid/Surfaces: Converts the selected mesh features to multi-solids or individual surfaces. To create solids, the mesh features must form closed meshes.
    2. Composite: Converts the selected mesh features to a single composite feature.
    3. Delete Original: Deletes the selected mesh features after conversion.

Set the default project location

Inventor saves the new projects in your document folder. To set a different default location

  1. In the Tools menu select Application Options
  2. On the File tab click the yellow folder icon next to Project folder and set the desired location.

To save the solid model as an STL 3D mesh

  1. Open the Inventor Parts (.ipt) or Inventor Assembly (.iam) file in Autodesk Inventor,
  2. Click the Inventor icon in the upper left corner,
  3. Click the small arrow next to Save As,
  4. In the submenu select Save Copy As,
  5. In the Save as type dropdown select STL Files,
  6. Enter a name for the file and click Options…,
  7. Select Source Units to make sure the size of the mesh is identical to the objects in the Inventor document,
  8. Click OK to close the Options window,
  9. Click Save to write the file to the disk.

Recommended 3D Printer settings

There are many 3D printers, filaments, and project types out there, so the variations of 3D printer settings are almost limitless. This page contains recommended settings for the most common 3D printing jobs, printers, and materials.

Printing materials

Filament material Shore A hardness Shrinkage Platform adhesion Advantages
PLA Blue painters tape  Less warping, No heating bed required, Eco-friendly, Odorless
ABS Kapton tape or Hairspray  Prints at higher temperature, Durable, Requires less manual finishing, Process in acetone for polished finish, UV resistant
PETG Blue painters tape or Kapton tape or Glass bed  Hydrophobic (does not absorb moisture), Odorless, Environmentally safe, Easy adhesion to a number of surfaces, No heating bed required
PPLA Blue painters tape or Kapton tape  Less warping than PLA, Eco-friendly, No heating bed required, Odorless
TPE 85A (very soft)  1.2 – 3.0% Blue painters tape or Kapton tape  Flexible, Easy to clean, Will adhere to most surfaces
TPU 94A (pretty soft)  0.8 – 1.8% Blue painters tape or Kapton tape  Flexible, Easy to clean, Will adhere to most surfaces
Filament material Strength Ease of use Odorless Felxibility Chemical resistance Abrasion resistance
PLA  [][][][  [][][][]  [][][][][]  [][][
ABS  [][][][]  [][][][  [] [  [][]
PETG  [][][][][  [][][][][  [][]  [][
PPLA  [][][][  [][][][][  [][][][][]  [][][
TPE  [][][]  [][][]  [][][][][]  [][][][][]  [][][]  [][]
TPU  [][][]  [][][][]  [][][][][]  [][][][][  [][][][]  [][][][][]

Printer settings for filament type

Filament material Nozzle temperature range (recommended) Build platform temperature range (recommended) Print speed
3D Solutech PLA
1.75 mm  and 3 mm
190-220 °C
(205 °C)
0-60 °C
(50 °C)
50 mm/s
Hatchbox PLA
1.75 mm  and 3 mm
180-210 °C
(195 °C)
0-60 °C
(50 °C)
50 mm/s
Hatchbox ABS
1.75 mm  and 3 mm
210-240 °C
(225 °C)
55- 85 °C 50 mm/s
Hatchbox PETG
1.75 mm  and 3 mm
230-260 °C 55- 85 °C 50 mm/s
Hatchbox PPLA
1.75 mm  and 3 mm
180-220 °C 55- 85 °C 50 mm/s
Hatchbox TPU
1.75 mm  and 3 mm
180-210 °C 55- 85 °C 30 mm/s

Printer settings for job type

For the best look, select the closest recommended layer height for your printer. See Layer Height below for the explanation.

Job type Layer height (mm) Fill density (%) Print speed (mm/s) Minimal layer cool time (sec)
Decorative 0.1 15 50 3
Light duty, mainly straight pull (casing, rotor blades)  0.1 30 50 3
Light duty (fast printing of parts with low load, where vertical surfaces are not visible) 0.3 30 50 3
Medium duty (shafts, casing with load) 0.1 50 50 5
Medium heavy-duty (structural elements with high load, lighter weight) 0.1 70 50 7
Heavy duty (structural elements with high load, motor brackets) 0.1 100 50 10
Extra heavy duty (nuts, bolts, gears, arms) 0.1 100 20 10

Layer height

The 3D printer extrudes the melted material layer-by-layer to build the object, so you will always see horizontal lines on the side of the print. The stepper motor, that controls the Z axis, moves the head or the platform in small steps. Every printer has a minimum resolution, that is the distance the head or the platform moves for a single step of the stepper motor. The stepper motor cannot stop between steps, so that is the minimum distance the head or the platform can move. If you select a layer height that is a multiple of the minimum resolution, the lines on the side of the product will be nice and even. If the layer height is not exactly the multiple of the minimum resolution, you will see lines in waves, that is called aliasing. Regular ink printers use the same technique to compensate for the not perfect harmony between the physical resolution of the printer, and the resolution of the printed picture. The following table contains the recommended layer heights for the most common 3D printers. The print quality is significantly reduced when the layer height is greater than 80% of the nozzle diameter. In the case of the usual 0.4 mm nozzle diameter, the maximum recommended layer thickness is 0.32 mm.

Cura, the popular slicer program works in microns and truncates the layer height to three decimal digits. The numbers in bold will be correctly represented in Cura, the rest can produce slightly smaller objects on the Z (vertical) axis.

Monoprice Select Mini
0.043750
0.087500
0.131250
0.175000
0.218750
0.262500
0.306250
0.350000

Spool weights

To help you to estimate the amount of remaining filament on the spool, the following table contains the weight of the empty spools.

Product Empty spool weight
Hatchbox 1kg 310 g