Skip to content
The Chat Archive
chatgpt-4o-latest-20250326· OpenAI LMArena Human Preference 140K

how can I install brew on macOS via puppet? (for example using an exec resource)

  1. User

    how can I install brew on macOS via puppet? (for example using an exec resource)

  2. Assistant

    To install Homebrew on macOS using Puppet, you can use the exec resource type to run the standard Homebrew installation command. Puppet's exec resource allows you to execute shell commands, making it suitable for tasks like installing software.

    Here's a basic example of how to install Homebrew using a Puppet exec resource:

    ✅ Puppet Manifest Example

    exec { 'install_homebrew':
      command => '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
      creates => '/opt/homebrew/bin/brew',  # Prevents re-running if already installed (M1+/ARM Macs)
      user    => 'your_username',           # Replace with the actual user (e.g., 'john')
      environment => [
        'NONINTERACTIVE=1',
      ],
      path    => ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'],
    }
    

    🔍 Explanation:

    • command: The standard Homebrew install script. We wrap it in /bin/bash -c for proper execution.
    • creates: Prevents the exec from running again if Homebrew is already installed. Adjust the path based on your architecture:
      • Intel Macs: /usr/local/bin/brew
      • Apple Silicon (M1/M2): /opt/homebrew/bin/brew
    • user: Homebrew must be installed as a non-root user. Replace 'your_username' with the appropriate macOS user.
    • NONINTERACTIVE=1: Makes the installation non-interactive (required for automation).
    • path: Required so that the shell can find curl and other basic tools.

    ❗ Notes:

    1. Do not run this as root. Homebrew refuses to install as root.
    2. You may need to configure Puppet to use the correct environment/user context when applying the manifest.
    3. Make sure Xcode command line tools are installed (xcode-select --install) — you can add another exec to handle this if needed.

    ✅ Optional: Ensure Xcode Tools Are Installed

    Add this exec before installing Homebrew:

    exec { 'install_xcode_cli':
      command => 'xcode-select --install',
      unless  => 'xcode-select -p',
      user    => 'your_username',
      path    => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
    }
    

    Let me know if you’re using a specific Puppet setup (e.g., Hiera with modules), and I can provide a more tailored solution!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.