Environment problem when administering macos with saltstack tools

81 views Asked by At

I have a few dozen mac computers on which I have a task to install various software (putty, git, draw-io, mosquitto), as well as to curtail the user's permissions (e.g. so that the user cannot download software himself). I manually installed saltstack on each of these computers, then ran salt master and accepted all keys. I then wrote some .sls files to install po, however I get an error every time:

     ID: homebrew
        Function: pkg.installed
          Result: False
         Comment: Unable to run command '['brew', '--prefix']' with the context '{'cwd': '/var/root', 'shell': False, 'env': {'OLDPWD': '/', 'PATH':
 '/usr/bin:/bin:/usr/sbin:/sbin', 'PWD': '/opt/salt', 'XPC_FLAGS': '0x0',
 'XPC_SERVICE_NAME': '0', 'SHLVL': '0', 'LC_CTYPE': 'C', 'SSL_CERT_DIR':
 '/private/etc/ssl/certs', 'SSL_CERT_FILE': '/private/etc/ssl/cert.pem',
 'LC_NUMERIC': 'C', 'LC_TIME': 'C', 'LC_COLLATE': 'C', 'LC_MONETARY': 'C',
 'LC_MESSAGES': 'C', 'LC_PAPER': 'C', 'LC_NAME': 'C', 'LC_ADDRESS': 'C',
 'LC_TELEPHONE': 'C', 'LC_MEASUREMENT': 'C', 'LC_IDENTIFICATION': 'C',
 'LANGUAGE': 'C'}, 'stdin': None, 'stdout': -1, 'stderr': -2, 
'with_communicate': True, 'timeout': None, 'bg': False, 'close_fds': True}',
 reason: [Errno 2] No such file or directory: 'brew'
         Started: 17:51:13.166312
        Duration: 15.798 ms
         Changes:
    
              ID: putty
        Function: pkg.installed
          Result: False
         Comment: One or more requisite failed: mac.software.putty.homebrew
         Started: 17:51:13.182820
        Duration: 0.003 ms
         Changes:
    -----------
    Summary for MAC-08-mac.local

I have tried many options to fix the error. I downloaded brew as a separate file and tried to install it before I installed putty. I also tried changing the sudo_user variable in /etc/salt/minion, as well as just user, because I thought the error was in brew from root. Also tried the brew extension "Homebrew Cask", but the error is always the same. I found a thread on the narkive.com forum, where they said that the HOME environment variable is to blame. Actually, I stopped searching for it because I ran out of resources. So I would like to know from professional sysadmins or more knowledgeable people what is the matter and how to fix it (don't judge me harshly, I am a first time system administrator and I am just learning). Just in case I will attach the command I use to run the script:

salt 'MAC-08-mac.local' state.highstate saltenv=development

I am rooting myself (I tried rootless with sudo, but nothing changed). I run the script from the directory /opt/salt/development/mac/software. in software there are scripts such as putty.sls, visual-studio-code.sls.... And the file software-mac.sls, which is located in /opt/salt/development/mac, is launched. It lists the files that are launched via inclusion (I tried to repeat the architecture from the book "Salt Cookbook" by Aniban Saha). As a possible error variant I will also show putty.sls:

putty:
  pkg.installed:
    - require:
      - pkg: homebrew

also homebrew.sls:

homebrew:
  pkg.installed

and /opt/salt/development/mac/software-mac.sls:

include:
#soft
  - software.homebrew
  - software.putty

I would be extremely grateful for any information on the topic and links to literature that may advance this issue :)

1

There are 1 answers

7
OrangeDog On

pkg.installed uses Homebrew to install things on macOS. Therefore it is not possible to use it to install Homebrew. Hence the error about not being able to find brew.

You need to install Homebrew first via some other means (e.g. a macpackage.installed or cmd.run state) before any pkg states will work.


Alternatively, if you were expecting Salt to use MacPorts instead of Homebrew, add the following to the minion config:

providers:
  pkg: mac_portspkg

Similarly, MacPorts would need to be installed first before any pkg states are run.