Skip to content

Instantly share code, notes, and snippets.

@jasonrm
Last active November 10, 2023 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasonrm/5268574 to your computer and use it in GitHub Desktop.
Save jasonrm/5268574 to your computer and use it in GitHub Desktop.

Salt States

top.sls

base:
  'os:MacOS':
    - match: grain
    - homebrew
  '*':
    - nginx

homebrew/init.sls

git-homebrew:
  git.latest:
    - name: git://github.com/mxcl/homebrew.git
    - rev: master
    - target: /usr/local/homebrew


bin-brew:
  file.symlink:
    - name: /usr/local/bin/brew
    - target: /usr/local/homebrew/bin/brew
    - require:
      - git: git://github.com/mxcl/homebrew.git

dir-usr-local:
  file.directory:
    - name: /usr/local
    - user: root
    - group: admin
    - file_mode: 744
    - dir_mode: 755
    - recurse:
      - user
      - group
    - require:
      - git: git-homebrew
      - file: bin-brew

nginx/init.sls

nginx:
  pkg:
    - installed

Pre-Install (done before each version)

$ python -V
Python 2.7.2
$ chown -R jason:wheel /usr/local
$ rm -rf /usr/local/lib/python2.7/site-packages/*
$ rm -rf /Library/Python/2.7/site-packages/*
$ easy_install pip

v0.13.3

$ pip install -Iv https://github.com/saltstack/salt/archive/v0.13.3.tar.gz
$ salt --version
salt 0.13.3
$ salt-call state.highstate --local -c .
[INFO    ] Loaded configuration file: /Users/jason/git-local/salt-states/minion
[WARNING ] Both 'dmidecode' and 'lspci' failed to execute, either because they do not exist on the system of the user running this instance does not have the necessary permissions to execute them. Grains output might not be accurate.
[INFO    ] Executing command 'ps auxwww' in directory '/Users/jason'
[WARNING ] Both 'dmidecode' and 'lspci' failed to execute, either because they do not exist on the system of the user running this instance does not have the necessary permissions to execute them. Grains output might not be accurate.
[INFO    ] Loading fresh modules for state activity
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/modules'
[INFO    ] Syncing modules for environment 'base'
[INFO    ] Loading cache from salt://_modules, for base)
[INFO    ] Caching directory '_modules' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/states'
[INFO    ] Syncing states for environment 'base'
[INFO    ] Loading cache from salt://_states, for base)
[INFO    ] Caching directory '_states' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/grains'
[INFO    ] Syncing grains for environment 'base'
[INFO    ] Loading cache from salt://_grains, for base)
[INFO    ] Caching directory '_grains' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/renderers'
[INFO    ] Syncing renderers for environment 'base'
[INFO    ] Loading cache from salt://_renderers, for base)
[INFO    ] Caching directory '_renderers' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/returners'
[INFO    ] Syncing returners for environment 'base'
[INFO    ] Loading cache from salt://_returners, for base)
[INFO    ] Caching directory '_returners' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/outputters'
[INFO    ] Syncing outputters for environment 'base'
[INFO    ] Loading cache from salt://_outputters, for base)
[INFO    ] Caching directory '_outputters' for environment 'base'
[INFO    ] Loading fresh modules for state activity
[INFO    ] Executing state git.latest for git://github.com/mxcl/homebrew.git
[INFO    ] Executing command 'git rev-parse HEAD' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git rev-parse master' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git checkout  master ' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git symbolic-ref -q HEAD > /dev/null' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git pull ' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git rev-parse HEAD' in directory '/usr/local/homebrew'
[INFO    ] No changes made for git://github.com/mxcl/homebrew.git
[INFO    ] Executing state file.symlink for /usr/local/bin/brew
[INFO    ] No changes made for /usr/local/bin/brew
[INFO    ] Executing state file.directory for /usr/local
[ERROR   ] {'group': 'admin', 'user': 'root'}
[INFO    ] Executing state pkg.installed for nginx
[INFO    ] Executing command 'brew list --versions ' in directory '/Users/jason'
[INFO    ] No changes made for nginx
local:
----------
    State: - git
    Name:      git://github.com/mxcl/homebrew.git
    Function:  latest
        Result:    True
        Comment:   
        Changes:   
----------
    State: - file
    Name:      /usr/local/bin/brew
    Function:  symlink
        Result:    True
        Comment:   The symlink /usr/local/bin/brew is present
        Changes:   
----------
    State: - file
    Name:      /usr/local
    Function:  directory
        Result:    False
        Comment:   Failed to change group to admin
        Changes:   group: admin
                   user: root
                   
----------
    State: - pkg
    Name:      nginx
    Function:  installed
        Result:    True
        Comment:   Package nginx is already installed
        Changes:   

Checking permissions. Looks like eveything is correct (at least at the base path) despite reporting it failed?

$ ls -la /usr/local/
total 0
drwxr-xr-x   12 root  admin   408 Mar 28 00:42 .
drwxr-xr-x@  13 root  wheel   442 Mar 16 00:43 ..
drwxr-xr-x    3 root  admin   102 Mar 28 00:42 Frameworks
drwxr-xr-x  159 root  admin  5406 Mar 28 19:59 bin
drwxr-xr-x    6 root  admin   204 Mar 23 11:25 etc
drwxr-xr-x   10 root  admin   340 Mar 26 23:23 homebrew
drwxr-xr-x   36 root  admin  1224 Mar 26 23:25 include
drwxr-xr-x  148 root  admin  5032 Mar 26 23:25 lib
drwxr-xr-x   46 root  admin  1564 Mar 28 00:42 opt
drwxr-xr-x    6 root  admin   204 Mar 20 21:47 sbin
drwxr-xr-x   26 root  admin   884 Mar 26 23:45 share
drwxr-xr-x    4 root  admin   136 Mar 21 22:07 var

v0.14.0

$ pip install -Iv https://github.com/saltstack/salt/archive/v0.14.0.tar.gz
$ salt --version
salt 0.14.0
$ salt-call state.highstate --local -c .
[INFO    ] Loaded configuration file: /Users/jason/git-local/salt-states/minion
[WARNING ] Both 'dmidecode' and 'lspci' failed to execute, either because they do not exist on the system of the user running this instance does not have the necessary permissions to execute them. Grains output might not be accurate.
[CRITICAL] Failed to load grains defined in grain file core.ip4 in function <function ip4 at 0x108b75848>, error:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/salt/loader.py", line 787, in gen_grains
    ret = fun()
  File "/Library/Python/2.7/site-packages/salt/grains/core.py", line 747, in ip4
    ips = salt.utils.socket_util.ip4_addrs()
  File "/Library/Python/2.7/site-packages/salt/utils/socket_util.py", line 307, in ip4_addrs
    ifaces = interfaces()
  File "/Library/Python/2.7/site-packages/salt/utils/socket_util.py", line 298, in interfaces
    ifaces = _interfaces_ifconfig(cmd)
NameError: global name 'cmd' is not defined

[INFO    ] Executing command 'ps auxwww' in directory '/Users/jason'
[WARNING ] Both 'dmidecode' and 'lspci' failed to execute, either because they do not exist on the system of the user running this instance does not have the necessary permissions to execute them. Grains output might not be accurate.
[CRITICAL] Failed to load grains defined in grain file core.ip4 in function <function ip4 at 0x108fba6e0>, error:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/salt/loader.py", line 787, in gen_grains
    ret = fun()
  File "/Library/Python/2.7/site-packages/salt/grains/core.py", line 747, in ip4
    ips = salt.utils.socket_util.ip4_addrs()
  File "/Library/Python/2.7/site-packages/salt/utils/socket_util.py", line 307, in ip4_addrs
    ifaces = interfaces()
  File "/Library/Python/2.7/site-packages/salt/utils/socket_util.py", line 298, in interfaces
    ifaces = _interfaces_ifconfig(cmd)
NameError: global name 'cmd' is not defined

[INFO    ] Loading fresh modules for state activity
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/modules'
[INFO    ] Syncing modules for environment 'base'
[INFO    ] Loading cache from salt://_modules, for base)
[INFO    ] Caching directory '_modules' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/states'
[INFO    ] Syncing states for environment 'base'
[INFO    ] Loading cache from salt://_states, for base)
[INFO    ] Caching directory '_states' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/grains'
[INFO    ] Syncing grains for environment 'base'
[INFO    ] Loading cache from salt://_grains, for base)
[INFO    ] Caching directory '_grains' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/renderers'
[INFO    ] Syncing renderers for environment 'base'
[INFO    ] Loading cache from salt://_renderers, for base)
[INFO    ] Caching directory '_renderers' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/returners'
[INFO    ] Syncing returners for environment 'base'
[INFO    ] Loading cache from salt://_returners, for base)
[INFO    ] Caching directory '_returners' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/outputters'
[INFO    ] Syncing outputters for environment 'base'
[INFO    ] Loading cache from salt://_outputters, for base)
[INFO    ] Caching directory '_outputters' for environment 'base'
[INFO    ] Loading fresh modules for state activity
git://github.com/mxcl/homebrew.git
git-homebrew
bin-brew
[INFO    ] Executing state git.latest for git://github.com/mxcl/homebrew.git
[INFO    ] Executing command 'git rev-parse HEAD' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git rev-parse master' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git checkout  master ' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git symbolic-ref -q HEAD > /dev/null' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git pull ' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git rev-parse HEAD' in directory '/usr/local/homebrew'
[INFO    ] No changes made for git://github.com/mxcl/homebrew.git
[INFO    ] Executing state file.symlink for /usr/local/bin/brew
[INFO    ] No changes made for /usr/local/bin/brew
[INFO    ] Executing state file.directory for /usr/local
[ERROR   ] No changes made for /usr/local
[INFO    ] Executing state pkg.installed for nginx
[ERROR   ] No changes made for nginx
local:
----------
    State: - git
    Name:      git://github.com/mxcl/homebrew.git
    Function:  latest
        Result:    True
        Comment:   
        Changes:   
----------
    State: - file
    Name:      /usr/local/bin/brew
    Function:  symlink
        Result:    True
        Comment:   The symlink /usr/local/bin/brew is present
        Changes:   
----------
    State: - file
    Name:      /usr/local
    Function:  directory
        Result:    False
        Comment:   An exception occured in this state: Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/salt/state.py", line 1208, in call
    *cdata['args'], **cdata['kwargs'])
  File "/Library/Python/2.7/site-packages/salt/states/file.py", line 953, in directory
    file_mode)
  File "/Library/Python/2.7/site-packages/salt/modules/file.py", line 1233, in check_perms
    if str(mode) != __salt__['file.get_mode'](name).lstrip('0'):
AttributeError: 'int' object has no attribute 'lstrip'

        Changes:   
----------
    State: - pkg
    Name:      nginx
    Function:  installed
        Result:    False
        Comment:   An exception occured in this state: Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/salt/state.py", line 1208, in call
    *cdata['args'], **cdata['kwargs'])
  File "/Library/Python/2.7/site-packages/salt/states/pkg.py", line 311, in installed
    result = _find_install_targets(name, version, pkgs, sources)
  File "/Library/Python/2.7/site-packages/salt/states/pkg.py", line 63, in _find_install_targets
    cur_pkgs = __salt__['pkg.list_pkgs']()
  File "/Library/Python/2.7/site-packages/salt/modules/brew.py", line 31, in list_pkgs
    cmd = 'brew list --versions {0}'.format(' '.join(args))
NameError: global name 'args' is not defined

        Changes:   

Checking permissions

$ ls -la /usr/local/
total 0
drwxr-xr-x   12 root  admin   408 Mar 28 00:42 .
drwxr-xr-x@  13 root  wheel   442 Mar 16 00:43 ..
drwxr-xr-x    3 root  admin   102 Mar 28 00:42 Frameworks
drwxr-xr-x  159 root  admin  5406 Mar 28 19:59 bin
drwxr-xr-x    6 root  admin   204 Mar 23 11:25 etc
drwxr-xr-x   10 root  admin   340 Mar 26 23:23 homebrew
drwxr-xr-x   36 root  admin  1224 Mar 26 23:25 include
drwxr-xr-x  148 root  admin  5032 Mar 26 23:25 lib
drwxr-xr-x   46 root  admin  1564 Mar 28 00:42 opt
drwxr-xr-x    6 root  admin   204 Mar 20 21:47 sbin
drwxr-xr-x   26 root  admin   884 Mar 26 23:45 share
drwxr-xr-x    4 root  admin   136 Mar 21 22:07 var

git branch - develop

$ pip install -Iv https://github.com/saltstack/salt/archive/develop.tar.gz
$ salt --version
salt 0.14.0
$ salt-call state.highstate --local -c .
[INFO    ] Configuration file path: /Users/jason/git-local/salt-states/minion
[WARNING ] Both 'dmidecode' and 'lspci' failed to execute, either because they do not exist on the system of the user running this instance does not have the necessary permissions to execute them. Grains output might not be accurate.
[INFO    ] Executing command 'ps auxwww' in directory '/Users/jason'
[WARNING ] Both 'dmidecode' and 'lspci' failed to execute, either because they do not exist on the system of the user running this instance does not have the necessary permissions to execute them. Grains output might not be accurate.
[INFO    ] Loading fresh modules for state activity
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/modules'
[INFO    ] Syncing modules for environment 'base'
[INFO    ] Loading cache from salt://_modules, for base)
[INFO    ] Caching directory '_modules' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/states'
[INFO    ] Syncing states for environment 'base'
[INFO    ] Loading cache from salt://_states, for base)
[INFO    ] Caching directory '_states' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/grains'
[INFO    ] Syncing grains for environment 'base'
[INFO    ] Loading cache from salt://_grains, for base)
[INFO    ] Caching directory '_grains' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/renderers'
[INFO    ] Syncing renderers for environment 'base'
[INFO    ] Loading cache from salt://_renderers, for base)
[INFO    ] Caching directory '_renderers' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/returners'
[INFO    ] Syncing returners for environment 'base'
[INFO    ] Loading cache from salt://_returners, for base)
[INFO    ] Caching directory '_returners' for environment 'base'
[INFO    ] Creating module dir '/var/cache/salt/minion/extmods/outputters'
[INFO    ] Syncing outputters for environment 'base'
[INFO    ] Loading cache from salt://_outputters, for base)
[INFO    ] Caching directory '_outputters' for environment 'base'
[INFO    ] Loading fresh modules for state activity
[INFO    ] Executing state git.latest for git://github.com/mxcl/homebrew.git
[INFO    ] Executing command 'git rev-parse HEAD' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git rev-parse master' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git checkout  master ' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git symbolic-ref -q HEAD > /dev/null' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git pull ' in directory '/usr/local/homebrew'
[INFO    ] Executing command 'git rev-parse HEAD' in directory '/usr/local/homebrew'
[INFO    ] No changes made for git://github.com/mxcl/homebrew.git
[INFO    ] Executing state file.symlink for /usr/local/bin/brew
[INFO    ] No changes made for /usr/local/bin/brew
[INFO    ] Executing state file.directory for /usr/local
[ERROR   ] {'mode': '744'}
[INFO    ] Executing state pkg.installed for nginx
[ERROR   ] No changes made for nginx
local:
----------
    State: - git
    Name:      git://github.com/mxcl/homebrew.git
    Function:  latest
        Result:    True
        Comment:   
        Changes:   
----------
    State: - file
    Name:      /usr/local/bin/brew
    Function:  symlink
        Result:    True
        Comment:   The symlink /usr/local/bin/brew is present
        Changes:   
----------
    State: - file
    Name:      /usr/local
    Function:  directory
        Result:    False
        Comment:   Failed to change mode to 744; Failed to change group to admin
        Changes:   mode: 744
                   
----------
    State: - pkg
    Name:      nginx
    Function:  installed
        Result:    False
        Comment:   An exception occured in this state: Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/salt/state.py", line 1214, in call
    *cdata['args'], **cdata['kwargs'])
  File "/Library/Python/2.7/site-packages/salt/states/pkg.py", line 311, in installed
    result = _find_install_targets(name, version, pkgs, sources)
  File "/Library/Python/2.7/site-packages/salt/states/pkg.py", line 63, in _find_install_targets
    cur_pkgs = __salt__['pkg.list_pkgs']()
  File "/Library/Python/2.7/site-packages/salt/modules/brew.py", line 31, in list_pkgs
    cmd = 'brew list --versions {0}'.format(' '.join(args))
NameError: global name 'args' is not defined

        Changes:   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment