Understanding and writing Salt states

In this recipe, we will learn one of the most important components of Salt states. We will understand what states are, how to write them, and how to use pillar data in writing states. We will configure a state called user to add a user to the development environment.

How to do it...

  1. First, we will create a directory for the state and populate it with state data:
    [root@salt-master ~]# mkdir \
    /opt/salt-cookbook/development/user
    [ root@salt-master ~]# touch \
    /opt/salt-cookbook/development/user/init.sls
    
  2. Edit /opt/salt-cookbook/development/user/init.sls and add the following contents:
    generic_user: user.present: - name: {{ pillar['dev_user']['name'] }} - shell: /bin/bash - home: /home/{{ pillar['dev_user']['name'] ...

Get Salt Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.