Puppet IIS Module Troubleshooting

Update on 3/30/17:  The Puppet IIS module has been updated, and the problem below has been eliminated.

Problem scenario:  You want Puppet to install IIS.  You install the IIS module and find the README.md file has this Puppet DSL (as of 12/13/16):

class mywebsite {
  iis::manage_app_pool {'my_application_pool':
    enable_32_bit           => true,
    managed_runtime_version => 'v4.0',
  }
   iis::manage_site {'www.mysite.com':
    site_path     => 'C:\inetpub\wwwroot\mysite',
    site_id       => '10'
    port          => '80',
    ip_address    => '*',
    host_header   => 'www.mysite.com',
    app_pool      => 'my_application_pool'
  }
...

It is also found on https://forge.puppet.com/puppet/iis

Why is there no comma after site_id? 

Solution:  This appears to be a typo in the syntax.  Any line besides the last should have a comma after it.  The open source movement has numerous advantages.  However, sometimes the community has to keep after the discovery of errors to make things work.

How Do I Assign User Input from a Bash Script to a Variable?

Question
How Do I Assign User Input from a Bash Script to a Variable?

Answer
The script below will read in two variables.  One will be referred to as $remoteIP and the other will be referred to as $remotePort later in the script.  The "$" symbol will evaluate the variable so its value will participate in the expression (e.g., for echoing to the screen or manipulating for conditional logic) later in the script.

#!/bin/bash
echo "Enter the IP address you want to test"
read remoteIP

echo "Enter the port number you want to test"
read remotePort

How Do You Install IIS In An Automated Way Without The Install-WindowsFeature Command?

Problem scenario:  You want to install IIS on Windows Server 2016 in an automated way.  But you are prevented from using Install-WindowsFeature or Add-WindowsFeature commands for business related reasons.
Normally something like this would work: 
Import-module servermanager; Add-WindowsFeature web-server, web-webserver -Verbose
What do you do?

Solution:  Use PowerShell with the System.Windows.Forms.SendKeys feature.

servermanager
start-sleep 2
[System.Windows.Forms.SendKeys]::SendWait{%"M"}
[System.Windows.Forms.SendKeys]::SendWait{%"M"}
start-sleep 1
[System.Windows.Forms.SendKeys]::SendWait("{DOWN}")
[System.Windows.Forms.SendKeys]::SendWait({~})
[System.Windows.Forms.SendKeys]::SendWait({nnn})
start-sleep 1
[System.Windows.Forms.SendKeys]::SendWait({w})
[System.Windows.Forms.SendKeys]::SendWait{~~}
start-sleep 1
[System.Windows.Forms.SendKeys]::SendWait("%{n}")
[System.Windows.Forms.SendKeys]::SendWait("%{n}")
[System.Windows.Forms.SendKeys]::SendWait("%{n}")
[System.Windows.Forms.SendKeys]::SendWait("%{n}")
[System.Windows.Forms.SendKeys]::SendWait("%{i}")

How do you update the hosts file on a Windows server with PowerShell?

Problem scenario:  Whenever you use PowerShell to append to the c:\windows\system32\drivers\etc\hosts file you get spaces before and after every character of every string.  The problem does not happen with ordinary text files.

To illustrate, here is a line of PowerShell code and take not of the destination flat file involved:
echo "8.8.8.8        continualintegration.com" >> c:\windows\system32\drivers\etc\hosts

The above code results in a line like this inside the file:
8 . 8 . 8 . 8         c o n t i n u a l i n t e g r a t i o n . c o m

Solution:  Copy the c:\windows\system32\drivers\etc\hosts to an intermediate file.  Update that file through your PowerShell script.  Then copy that file to c:\windows\system32\drivers\etc\hosts to overwrite it.

Installing Git 2.x on CentOS and Getting Passed Two Potential Problems

Notice that there are two problem scenarios and two solutions.

Problem scenario:  When installing Git on CentOS you get this error "http-push.c ... fatal error ... expat.h: No such file or directory"

Solution
Run this: yum install expat-devel

Problem scenario:  When running commands to install Git on CentOS, you use the "make" command.  But you get this error:  "git-compat.util.h:...: fatal error: openssl/ssl.h  No such file or directory."

Solution
Run this: yum install openssl-devel

Finally, for some good directions for installing Git 2.x on CentOS, see this link: http://tecadmin.net/install-git-2-x-on-centos-rhel-and-fedora/

How Do You Install Ansible on an AWS Instance of Linux SUSE?

Problem scenario
You want to use Ansible with Linux SUSE.  How do you install Ansible (the control node) on an AWS Instance of Linux SUSE?

Solution
Prerequisite
You must have 2.5 GB of memory (either in RAM or with a combination of RAM and swap space). For directions on how to configure swap space in the amount of 2 GB, see this posting. You have installed Git too.


Procedures
1.  Make sure your server is in a Security Group that allows it to have access to the Internet.

2.  Create a file called /tmp/ansible.sh with the following content:

zypper -n install python-setuptools
cd /tmp
git clone git://github.com/ansible/ansible.git --recursive
mv ansible /usr/local/
cd /usr/local/ansible
echo 'PATH="$PATH":/usr/local/ansible/bin' > /etc/profile.d/ansible.sh
python setup.py build
python setup.py install
echo 'Run "export PATH="$PATH":/usr/local/ansible/bin" to immediately start using Ansible'
echo 'Then you can run "ansible --version" to confirm it was installed'

3. Run it with sudo bash /tmp/ansible.sh. 

How Do You Automate a Process That Involve a GUI Operation with Powershell?

Question:  How Do You Automate a Process That Involve a GUI (e.g., to save an .xps or .oxps file) Operation with Powershell?  You do not want any part to be interactive.

Solution:  This applies to PowerShell version 4 and above.  This will save the content of c:\temp\contint.txt to goodName.xps in the default folder (often the user's Documents folder) without needing to attend to the process.

# These three lines (starting with "Add...", "set...", and "start..." ensure the XPS Viewer is functional:
Add-WindowsFeature XPS-Viewer  #this ensures the server has XPS viewer as a printer driver
set-service spooler manual  #if the printer spooler is disabled, this will not work
start-service spooler       #if the printer spooler is not working, the automation will not work

# These next lines print a file:
start-process -FilePath C:\temp\contint.txt -Verb print
start-sleep 1 #wait one second for the application to open
[System.Windows.Forms.SendKeys]::SendWait({"goodName"})  # This input a name into the GUI
[System.Windows.Forms.SendKeys]::SendWait({'~'})  # This saves the file with issuing "Enter"

# To learn more about the PowerShell-to-keyboard mapping, use this link:
http://www.vexasoft.com/pages/send-keyboardinput
# It is possible to use SendKeys to tab up, change the path where the .xps file is saved, and tab down to finally save it.
# The above code is a simple example of something that may be useful.
# To save to a .pdf, try this link.

How Do I Know If I Have a Safe Version of NTP on a Linux Server?

Question  How do I know if I have a safe version of NTP on a Linux server?

Background  The United States Computer Emergency Readiness Team's website indicates that this many versions of NTP are susceptible to a denial-of-service attack.

Answer  Run this command:  ntpd --version

The output should look something like this:

ntpd 4.2.8p9

If it is lower than that (e.g., ntpd 4.2.8p8), then you need to upgrade your ntp version.

How To Install and Configure Salt Stack on RedHat Linux (AWS Instances)

Problem scenario
You want to install SaltStack on RHEL instances for the first time on an AWS server.

Solution in Three Parts
(If you want instructions on how to do this with Debian/Ubuntu and/or Linux SUSE, see this posting.)

Part 1  Create a Salt Master Server
1.  Create a RHEL instance and put it in a Security Group that has access to the Internet for this initial setup, and has connectivity to the other server that will be the Salt Minion.  The IP address you would use is the internal IP address of the server (from an ifconfig command) and not the IP address seen in the EC2 console (one that you would use Putty to connect to).

2.  Assume the root user (sudo su -)

3.  Run these commands:
yum -y install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el7.noarch.rpm
yum -y install salt-master

4.  Verify it worked:
salt-master --version

5. Start the salt-master service:
systemctl start salt-master

Part 2  Create a Salt Minion Server
6.  Create a RHEL instance and put it in a Security Group that has access to the Internet for this initial setup and has connectivity to the other server that will be the Salt Master.   The IP address you would use is the internal IP address of the server (from an ifconfig command) and not the IP address seen in the EC2 console (one that you would use Putty to connect to).

7.  Assume the root user (sudo su -)

8.  Run these commands:
yum -y install https://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el7.noarch.rpm
yum -y install salt-minion

9.a.  vi /etc/salt/minion
9.b.  Search for "master: salt"
9.c.  Uncomment this line.  Change "salt" to "saltmaster" or the hostname of the salt master server.

10.   Update the /etc/hosts file to ensure it can resolve the saltmaster hostname via a ping.
11.  Run this command: salt-minion -l debug

Part 3  Configure Salt Master to Communicate With Salt Minion
12.  Log on to the Salt Master server as root.

13.  Run this: salt-key -L

The output should look something like this:

Accepted Keys:
Denied Keys:
Unaccepted Keys:
salt-minion1.continualintegration.com
Rejected Keys:

14.  Run this command:
salt-key -a salt-minion1.continualintegration.com
respond to the prompt with "Y" with no quotes and press enter.

15.  You are done.
Now these commands should work:

  salt '*' test.ping
  salt '*' disk.usage
  salt '*' cmd.run 'ls -l /etc'
  salt '*' network.interfaces
  salt '*' test.echo 'foo: bar'