How Do You Create a Windows 2016 Server with Vagrant and Oracle VirtualBox?

Problem scenario
You want to use Windows 2016 with 2 GB of RAM. You have Oracle VirtualBox installed on a Linux server. You want the VM to be able to communicate with the host or other VMs on the host. You have a license for Windows 2016. What should you do?

Solution
Prerequisite: You have Oracle VirtualBox set up. You know what adapters you can attach a VM to. (Options may include enp1s0, virbr0, virbr0-nic or others.)

  1. Install Vagrant.
  2. Run this command:
    gem list | grep libvirt
  3. Verify that libvirt's version is at least 0.6 or higher. If it is, go to step #2. If it is lower than that, use the following two commands (uncommented out):
# gem uninstall fog-libvirt
# gem install fog-libvirt

4. Run these two commands:

vagrant plugin install winrm
vagrant plugin install winrm-elevated

5. Use this as the Vagrantfile (but not for commercial purposes unless you have a license):

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "mwrock/Windows2016"
  config.vm.provider "virtualbox"
  config.vm.network :public_network, :bridge => "enp1s0", adapter: "1"
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
   config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
     vb.memory = "2048"
   end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
  1. Run this command: vagrant up
    Do not be alarmed if it hangs at the "default WinRM transport: negotiate" step.

You may see this (because there is only one adapter and it is a bridged adapter):

default: WinRM address: 127.0.0.1:55985
default: WinRM username: vagrant
default: WinRM execution_time_limit: PT2H
default: WinRM transport: negotiate
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

How Do You Filter the Output of an AWS CLI Command?

Problem scenario
You want to return only the JSON of the output that is related to a specific role -- not the entire list of an "aws iam list-roles" command. What do you do?

Solution
Prerequisite
You must have the AWS CLI installed. If you need assistance, see this posting.

Procedures
Use the "--query" flag. Often the syntax to structure a query in the results is the word to the right of the "list-" in an AWS CLI command. Such is the case for "aws iam list-roles":

Here is an example (just replace the "123456:role/foobar" with the Arn value right of the "arn:aws:iam" string):

aws iam list-roles --query 'Roles[?Arn==arn:aws:iam::123456:role/foobar]'

aws ec2 describe-subnets --query 'Subnets[?SubnetId==subnet-0a1234efgh]'

How Do You Write a Java Program to Accept a Character as Input and Do Something with It?

Problem scenario
You want to accept user input with a Java program. How do you write such a program?

Solution
Here is the program:

import java.util.Scanner;

public class acceptChar {

public static void main(String[] args) {
   System.out.println("Please enter a character, then press enter: ");
   Scanner in = new Scanner(System.in);
   char letter = in.next().charAt(0);
   System.out.println(letter);
  }
 }

Why Do Processes Get CPU Time on a Linux OS when Their Nice Level is Set for Unfavorable Scheduling?

Problem scenario
Some processes are a low priority for an OS given their nice level. Why do they eventually run when the OS is active and busy handling processes that have higher priorities? Wouldn't a nice level that indicates a low priority keep the process starved of receiving resources?

Answer
There is a round robin scheduling algorithm for the CPU to allocate time. When such processes in the question are not starved, it is because there is no lock primitive blocking the process from the CPU.

Experienced Linux administrators know that processes will complete, even if they have a low priority nice value (one near or equal to 19).

According to the influential book The Linux Programming Interface by Michael Kerrisk (page 734), a low priority nice value will not starve a process of CPU. The kernel will govern the specifics and there is variance in the round robin processing among Linux distributions and their respective kernel (page 734).

Modern kernels have a scheduling algorithm that put a greater weight on the nice value (page 734 of the same book). The nice values are like golf: higher is worse in that a -20 nice value corresponds with the highest priority.

One way to remember how the scheduling algorithm of a Linux kernel works is this: imagine owning a timeshare based on your golf score. Better golfers get lower scores; lower nice values are more important and get more time with the CPU. CPU time is shared in a round robin way.

Resource starvation can happen when there is a lock (such as a mutex or a semaphore) blocking access to code. Blocking access to certain code is a mechanism of synchronization. The elements involved with the control of the flow of a program (the order of execution) are to prevent the entry into certain parts of code under certain conditions. But some applications, even tested ones, do not account for scenarios the software engineer(s) did not think could happen. Therefore sometimes a process is starved from resources. Thorough testing of logic can help a programmer design a solution where no resource starvation happens.

How Do You Troubleshoot “ssh connect to host x.x.x.x port 22: Connection refused”?

Problem scenario
You get “ssh connect to host x.x.x.x port 22: Connection refused” when trying to SSH. What do you do?

Possible solution #1
Do you have the correct IP address? Can you copy and paste the IP address? Can you run "ip addr show" on different servers? Is the IP addressed used multiple times in different subnets? It could refer to different servers. Human error could contribute to this error.

Possible solution #2
Has openssh-server been installed? If you have a Debian or Ubuntu distribution of Linux, run this command: sudo apt -y install openssh-server

Possible solution #3
Is the sshd service running? Try sudo systemctl start sshd

Possible solution #4
Is port 22 blocked via a firewall, IDS, IPS, or router?

Possible solution #5
This only applies when you are trying to remote into your Mac system from another Linux server. On the Mac open System Preferences. Go to “Sharing”. Go to “Remote Login” and check it if it is unchecked. Now you can go back to the Linux system and try again.

What is User Data in AWS, Azure, or Terraform?

Problem scenario
You have heard about user data in AWS, Azure, or Terraform. What is it? What does user data include?

AWS User Data versus Terraform User Data

Answer for AWS
Generally it is a customization that the account owner configured to apply to an EC-2 instance when it first launches. It is either a shell script or a cloud-init directive that is used when an EC-2 instance is launched (according to Amazon's website).

Shell scripts that the customer provides are self-explanatory. The cloud-init directives are for SSH key configuration (according to Amazon's website).

Answer for Azure
"User data is a set of scripts or other metadata, that will be inserted to an Azure virtual machine at provision time." This was taken from Microsoft's website.

As of 10/31/21 in Azure, it can be called Custom Data or User Data. This picture was taken on Halloween of 2021:

We think it will only be called User Data in the future.

Answer for Terraform
It is one or more bash commands that run when a server is initially created and booted (according to page 14 of Terraform Up & Running).

A List of Python Books

1593279280Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming by No Starch Press
1593279922Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners by No Starch Press
1449355730Learning Python, 5th Edition by O'Reilly Media
0134692888Learn Python 3 The Hard Way (Zed Shaw's Hard Way Series) by Addison-Wesley Professional
1491957662Python for Data Analysis: Data Wrangling with Pandas, NumPy, and IPython by O'Reilly Media
0134853989Effective Python: 90 Specific Ways to Write Better Python (2nd Edition) (Effective Software Development Series) by Addison-Wesley Professional
1491946008Fluent Python: Clear, Concise, and Effective Programming by O'Reilly Media
B0867ZD31NCoding with Python: A Simple and Effective Guide to Coding With Python
1974431479A Smarter Way to Learn Python: Learn it faster. Remember it longer. by CreateSpace Independent Publishing Platform
1491919531Head First Python: A Brain-Friendly Guide by O'Reilly Media
1530051126Python for Everybody: Exploring Data in Python 3 by CreateSpace Independent Publishing Platform
0135404673Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud by Pearson
1449340377Python Cookbook, Third edition by O'Reilly Media
B0868TMGLDPython: 2 Books in 1: The Crash Course for Beginners to Learn Python Programming, Data Science and Machine Learning + Practical Exercises Included. (Artifical Intelligence, Numpy, Pandas)
1593278780Serious Python: Black-Belt Advice on Deployment, Scalability, Testing, and More by No Starch Press
1449357016Python Pocket Reference (Pocket Reference (O'Reilly)) by O'Reilly Media
B0836JR9G5Python: 4 Books in 1: Ultimate Beginner's Guide, 7 Days Crash Course, Advanced Guide, and Data Science, Learn Computer Programming and Machine Learning with Step-by-Step Exercises
1593274076Python for Kids: A Playful Introduction to Programming by No Starch Press, Incorporated
B0868PZBCJThe Python Bible 7 in 1: Volumes One To Seven (Beginner, Intermediate, Data Science, Machine Learning, Finance, Neural Networks, Computer Vision)
1492051365Introducing Python by O'Reilly Media
B0867BNK3DPython Data Science: A Simple and Effective Guide to Python Data Science
1641521759Coding for Kids: Python: Learn to Code with 50 Awesome Games and Activities by Rockridge Press
149205769XPython for DevOps: Learn Ruthlessly Effective Automation by O'Reilly Media
1119557593Python All-in-One For Dummies (For Dummies (Computer/Tech)) by For Dummies
1492024333Python For Finance by O'Reilly Media
B084VHN9M6Python for Beginners: 2 Books in 1: The Perfect Beginner's Guide to Learning How to Program with Python with a Crash Course + Workbook by FAF Publishing Ltd
B08FYPNKXPComputer Programming for Beginners: This Book Includes - Python, C++, Linux For Beginners And Hacking With Kali Linux. Learn to Program Steb by Step with This Collection
159327890XImpractical Python Projects: Playful Programming Activities to Make You Smarter by No Starch Press
B071Z2Q6TQPython (2nd Edition): Learn Python in One Day and Learn It Well. Python for Beginners with Hands-on Project. (Learn Coding Fast with Hands-On Project Book 1) by Learn Coding Fast
1492055433Artificial Intelligence in Finance: A Python-Based Guide by O'Reilly Media
1631595814Creative Coding In Python by Quarry Books
B085Q572RVPYTHON: 2 Books in 1: Python Programming & Data Science. Master Data Analysis from Scratch and Discover the Secrets of Machine Learning with Step-by-Step Exercises
1593275900Black Hat Python: Python Programming for Hackers and Pentesters by No Starch Press
1890774979Murach's Python Programming by Mike Murach & Associates
B085ZQGKW3Python Programming: A Comprehensive Smart Approach for Total Beginners to Learn Python Language Using Best Practices and Advanced Features by Everooks LTD
B07WNS7QWCCode Python, Award-Winning STEM Courses, Coding for Kids, Ages 10+ with Online Mentoring Assistance, Learn Computer Programming and Video Game Design, Code Amazing Games with Python (PC & Mac) by CodaKid
0262529629Introduction to Computation and Programming Using Python: With Application to Understanding Data by The MIT Press
B07BL37CDFPython Machine Learning Projects
1593278225Cracking Codes with Python: An Introduction to Building and Breaking Ciphers by No Starch Press
B086J9BTKLComputer Programming: This book includes: Learn Python + SQL Programming
B07RHG1WGFMachine Learning: The Absolute Complete Beginner’s Guide to Learn and Understand Machine Learning From Beginners, Intermediate, Advanced, To Expert Concepts by Newcos
B07MLG8Z6TProgramming: Programming for Beginners: 6 Books in 1: Python, Raspberry Pi and Machine Learning by Eddison
1491939362Think Python: How to Think Like a Computer Scientist by O'Reilly Media
1593276036Python Crash Course: A Hands-On, Project-Based Introduction to Programming by No Starch Press
B086J9ZWGDPython Programming: 3 Books in 1: Data Science Handbook, Data Analysis and Machine Learning with Python. A Crash Course to Learn Programming.
B086H4DMRWPython Programming for Beginners: Basic Language from Absolute Beginners to Intermediate. Learn Easily and Fast Data Science and Web Development in a Simple and Practical Way Step-by-Step
B0785Q7GSYPython Tricks: A Buffet of Awesome Python Features by Dan Bader (dbader.org)
1654136611Python for Data Analysis: The Ultimate Beginner's Guide to Learn Programming in Python for Data Science with Pandas and NumPy, Master Statistical Analysis, and Visualization by Independently published
1840788127Python In Easy Steps 2nd by In Easy Steps Limited
1491912057Python Data Science Handbook: Essential Tools for Working with Data by O'Reilly Media
1617294438Deep Learning with Python by Manning Publications
0596158106Programming Python: Powerful Object-Oriented Programming by O'Reilly Media
1590282752Python Programming: An Introduction to Computer Science, 3rd Ed. by Franklin, Beedle & Associates
1801071101Expert Python Programming: Master Python by learning the best coding practices and advanced programming concepts, 4th Edition by Packt Publishing

How Do You Fix the Error “The pkg-config script could not be found or is too old.”

Problem scenario
You run a command like "make deps", but you get this message "configure: error: The pkg-config script could not be found or is too old." What should you do?

Solution
For an Ubuntu/Debian distribution of Linux, run:

sudo apt-get install -y pkg-config

For a Red Hat distribution of Linux (e.g., CentOS/RHEL/Fedora), run this:

sudo yum install -y pkgconfig

For Archlinux OS, run this:

sudo pacman -S pkgconf

These solutions were adapted from https://stackoverflow.com/questions/23202146/cannot-find-pkg-config-error

How Do You Troubleshoot the Message “error: too early for operation, device not yet seeded or device model not acknowledged”?

Problem scenario
You are using a Red Hat Distribution of Linux (e.g., CentOS/RHEL/Fedora). You try to run a snap command. You see this message: "error: too early for operation, device not yet seeded or device model not acknowledged". What should you do to get the snap command to work?

Solution
Run this command:

sudo dnf reinstall snapd

This solution was taken from this posting:
https://forum.snapcraft.io/t/error-too-early-for-operation-device-not-yet-seeded-or-device-model-not-acknowledged/12421/17

How Do You Get EC-2 Instances to Get IP Addresses by Default?

Problem scenario
In AWS when you try to create an EC-2 instance, on step #3 to "Configure Instance Details", you are not getting an auto-assigned public IP address. You see this message:

"No default subnet found
Please choose another subnet in your default VPC, or choose another VPC."

What should you do?

Solution
As of November 2020, you cannot create a default subnet with the AWS Management Console (to the best of our knowledge and this posting https://docs.aws.amazon.com/vpc/latest/userguide/default-vpc.html#create-default-subnet that says "Currently, you can create a default subnet using the AWS CLI, an AWS SDK, or the Amazon EC2 API only.").

Procedures
Run a command like this (but change the us-east-2a to the one of your choice):
aws ec2 create-default-subnet --availability-zone us-east-2a