CLI: One of the Tools for Learning Puppet

Welcome back! If you are reading this post, I’m assuming that you and your cat have read the introductory post in this series about learning the tools you need to learn Puppet, and that you’ve successfully downloaded the Puppet Learning VM.

We are now going to use the command line to interface with the computer. Instead of clicking on folders to get from place to place, we will maneuver sans mouse (Sorry, kitty, I know you like the mice, but we are learning to do more with less).

Let’s Try Terminal / Command Line

FossWire.com has an excellent cheat sheet of useful command line interface (CLI) commands that you might want to print out. Here, we’re going to try out a few of the more straightforward ones. Please note that the CLI instructions in this post are for Unix / OSX (the VM we downloaded is a CentOS Linux machine, so all of the commands will work there). If you want to use CLI on Windows, there will be a few minor differences.

Type the commands that look like this into terminal exactly as shown (do not change capitalized text into lowercase, or vice versa), and hit the Enter key after each one. Terminal should display the italicized information to the right of the command. If it doesn’t, we should find an engineer in the kitchen and ask them to help us figure out what’s wrong. Crap, you don’t have an engineer in your kitchen? Cruise over to Stack Overflow, a site where programmers of all levels ask questions and share answers. If you can't locate the answer you need, open up a new question.

Here are the first commands we’re going to try out:

  • Type in date to shows the current date and time
  • Type in cal to view a calendar of this month
  • Type in whoami to show the user identity you logged in with

Bam! You just used command line!

Now let’s explore the computer and learn some more useful commands.

If you ever forget where you are, you can type pwd to discover your present working directory. We are logged into the root directory, which means that we are in the main directory of the root user (which basically means we have the power to do anything we want, mwahaha...).

ls is for list, and it lists all of the folders and files where you are. Try it now. Man, this VM is mostly just installation stuff and Puppet stuff.

cd is for change directory, and it moves you from one place to another. For instance, you can type cd examples, and it will move you into the examples folder, just as if you had clicked it in a window. Once you start typing “examples,” you should be able to hit tab and it will auto-complete if you have enough of the word typed to distinguish it from other things in the ls. (For example, typing “ins” won’t be enough to get you to “install.log,” since there are other files that begin with “install.”) Please note that directory names are case sensitive. Try cd examples now.

mkdir is for make directory, and it creates a new folder / directory in the place where you are. Let’s make a folder for all the files your cat is going to be making by typing mkdir kitten_code. (You can name it whatever you want, but spaces make life more difficult, so I would recommend using an underscore_between_words or using.periods.instead.of.spaces. (You can always look at the rules and regulations for naming files and directories.)

If you would like to make a directory outside of the one you are currently in, you could typemkdir -p ~/examples/other_folder/a_folder_under_THAT. Remember, ~ means home directory. The -p is for parent, so the parent folder will be created if it isn’t already there (as in the case of creating other_folder before creating a_folder_under_THAT).

Now change into the directory you just made (cd kitten_code).

touch creates (or updates) a file. close up of fingers from “The Creation of Adam” from the Sistine Chapel, by Michaelangelo

Be sure to add the file type (.txt, .csv, .pdf, etc) after the file name, and follow the same naming rules as for the folder / directory. Type touch ball_of_yarn.txt

You could use a text editor such as vim or nano to edit this file, but we will go over that in the next post.

If we are now done, we can either type cd to go all the way up to the home directory, or type cd .. to go to the directory just one level up.

Now let’s look at two things that are kinda similar: mv for move and cp for copy. The syntax looks like this:

mv current/location/of/file.txt new/location/file.txt
or
cp current/location/of/file.txt new/location/file.txt

Moving a file is really just changing the file path name, so you can also use mvto rename a file. If you would like to move ball_of_yarn.txt to the home directory and change the file’s name to wheres_my_food.txt, you would type:
mv ~/examples/kitten_code/ball_of_yarn.txt ~/wheres_my_food.txt

To make a copy in the same folder / directory, or somewhere else on your computer, and keep the original file name as it is, you would use cp:

cp ~/examples/kitten_code/ball_of_yarn.txt ~/wheres_my_food.txt

Groovy, we can move around and make folders and files; what’s next?

Installing Things

picture of a mad scientist, obviously up to something nefarious

Now is a good time to remind your cat about computer hygiene: being careful about what to download and install, and being diligent about backups.

First: backups. Keeping regular backups is a good, nay, an essential part of being a responsible computer owner. This way, if Something Happens, you know you don’t have to start from scratch to rebuild your computer-life.

Next: Have “the talk” with your cat about downloading. You’re going to be downloading and installing things, and you want the cat to exercise good judgment. Here’s a useful article about how to judge whether something is safe to download.

Installation tools allow you to install a program, or “package,” as we often say, and are specific to the operating system (OS) you are working on. (The operating system is the type of computer, like Windows, Mac, Linux, etc.) We are going to use a tool called yum, because it is super-groovy for a Linux OS. (If you would like to check out installation tools for Windows, this page has info; if you would like to check out installation tools for Mac, go to this page.)

We could use RPM (Red Hat Package Manager) to install a package, but first we would need to find out what other packages need to be installed before the package you actually want can function (these packages you need to install first are called “dependencies”). Luckily, yum will automatically update and figure out all of your dependencies for you. And rather than having to type several commands, you can just type:
yum install subversion.

Yum figures out what the most recent version is, gets that package for you, and makes everything groovy. Note that the subversion package was already sitting on our VM like an unopened birthday present, and that rpm / yum are just installing / opening up the package. If you are connected to the internet and have a list of yum package repositories defined, then yum would go out and find the packages on the web.

Congratulations, you are now reasonably well equipped to make Things happen on your computer via command line! The next blog post will cover editing files in command line with vim! Ending on a positive note means lots of exclamation points! Which are called “bangs” when you are talking about computers, not “punctuation” like when you talk about grammar! Learning!

Extras!

A file path name is really the file’s name (like “ball_of_yarn.txt”) plus the “path” one has to take to get there. For example, I have a folder on my desktop called “not as useful things.” In that folder is file called tableflip.gif. My laptop is set up to have multiple users, and I am logged in as tiffany. The file path name for that .gif is
~/Users/tiffany/Desktop/not as useful things/tableflip.gif.

Really? You want to try installing by RPM? OK...
Type rpm -i subversion-1.6.11-10.el6_5.x86_64.rpm. Here, -i tells the computer to install the subversion package (as long as it’s in the same directory that you are running this command from). Later, we would type rpm -Uvh subversion-1.6.11-10.el6_5.x86_64.rpm. Here, -Uvh means "upgrade
package," so it finds any older versions and deletes them before installing the newest version.

If you are having trouble installing packages via yum, you should try puppet resource yumrepo base enabled=1 and puppet resource yumrepo epel enabled=1. Or check out Stack Overflow, an excellent resource for all your computer woes.

RESOURCES

Tiffany Longworth is a business systems analyst at Puppet Labs.

Learn More

Leave a comment

Tradeshow
Sep 3
Puppet Practitioner
Sep 9
Speaking Engagement
Sep 11
Tradeshow
Sep 12