Skip to content
Nitin Madhok edited this page Jun 18, 2015 · 5 revisions

top.sls

The top file is used to map what SLS modules get loaded onto what minions via the state system.

Here is a simple example of file_roots in the master configuration:

file_roots:
  base:
    - /srv/salt

Here is a simple, single environment top.sls file:

base:
  '*':
    - core
  'os:Ubuntu':
    - match: grain
    - repos.ubuntu

pkg / file / service

apache:
  pkg.installed:
    - version: 2.2.23
  service.running:
    - enable: True
/var/www/index.html:      # ID declaration
  file:                   # state declaration
    - managed             # function
    - source: salt://webserver/index.html
    - user: root
    - group: root
    - mode: 644
    - require:            # requisite declaration
      - pkg: apache       # requisite reference

file

Manages files.

FUNCTIONS

  • absent – verify that a file or directory is absent
  • accumulated - prepare accumulator which can be used in template in file.managed
  • append – put some text at the end of file
  • comment – comment out some lines
  • directory – ensure that a directory is present
  • exists – ensure that a directory or file is present
  • managed – this file is managed by the salt master and can be run through templating system
  • patch – apply a patch to a file
  • recurse – recurse through a subdirectory on master
  • rename – rename a file
  • replace – edit a file
  • symlink – create a symlink
  • touch – create an empty file or update m/atime
  • uncomment - uncomment lines in a file
/etc/http/conf/http.conf:
  file.managed:
    - source: salt://apache/http.conf
    - user: root
    - group: root
    - mode: 644
    - template: jinja
    - context:
        custom_var: "override"
    - defaults:
        custom_var: "default value"
        other_var: 123

pkg

Manage software packages.

FUNCTIONS

  • installed – verify if a package is installed
  • latest – verify that the package is the latest version
  • purged - verify if the package is removed, if not removes the package and all configuration files
  • removed – verify if the package is removed, if not removes the package
httpd:
  pkg.installed
    - repo: mycustomrepo
    - skip_verify: True
    - version: 2.0.6~ubuntu3

service

Manage system daemons.

FUNCTIONS

  • dead
  • disabled
  • enabled
  • mod_watch
  • running
apache:
  service.running
    - name: httpd
    - enable: True
    - sig: httpd

cmd

Execution of arbitrary commands.

FUNCTIONS

  • mod_watch
  • run
  • script
  • wait
  • wait_script
date > /tmp/salt-run:
  cmd.run

cron

The cron state module allows for user crontabs to be cleanly managed.

FUNCTIONS

date > /tmp/crontest:
  cron.present:
    - user: root
    - minute: 7
    - hour: 2

absent

file - provides file.managed-like functionality (templating, etc.) for a pre-made crontab file, to be assigned to a given user

present

user

The user module is used to create and manage user settings, users can be set as either absent or present.

FUNCTIONS

fred:
  user.present:
    - fullname: Fred Jones
    - shell: /bin/zsh
    - home: /home/fred
    - uid: 4000
    - gid: 4000
    - groups:
      - wheel
      - storage
      - games

testuser:
  user.absent

group

The group module is used to create and manage unix group settings, groups can be either present or absent.

FUNCTIONS

  • present
  • absent
cheese:
  group.present:
    - gid: 7648
    - system: True

git

Interaction with Git repositories.

https://github.com/saltstack/salt.git:
  git.latest:
    - rev: develop
    - target: /tmp/salt

host

Management of addresses and names in hosts file.

salt-master:
  host.present:
    - ip: 192.168.0.42

kmod

Loading and unloading of kernel modules.

kvm_amd:
  kmod.present
pcspkr:
  kmod.absent

mount

Mounting of filesystems.

/mnt/sdb:
  mount.mounted:
    - device: /dev/sdb1
    - fstype: ext4
    - mkmnt: True
    - opts:
      - defaults

sysctl

Configuration of the Linux kernel using sysctrl.

vm.swappiness:
  sysctl.present:
    - value: 20