Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning SaltStack

You're reading from   Learning SaltStack Learn how to manage your infrastructure by utilizing the power of SaltStack

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781784394608
Length 174 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Colton Myers Colton Myers
Author Profile Icon Colton Myers
Colton Myers
Arrow right icon
View More author details
Toc

Our first state

Without further ado, let's write our first state. All Salt-specific files that aren't Python files end in the extension .sls. By default, states are located in the /srv/salt directory. We created this directory in the previous chapter, but if you didn't follow along there, make this directory now, as follows:

# mkdir -p /srv/salt
# cd /srv/salt

Inside of this directory, let's create a file called apache.sls, as shown in the following line of code:

# vim apache.sls

Here are the contents of that file:

install_apache:
  pkg.installed:
    - name: apache2

Note

State files are formatted using Yet Another Markup Language (YAML). The most common syntax errors in state files are forgetting the colons at the end of the first two lines, so watch out for that. More information about YAML can be found at http://www.yaml.org/.

Let's run our state. To apply states to our minions, we actually use the state execution module. For now, we will use the state.sls function...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image