I'm trying to execute a Python script using SaltStack's LocalClient on a Salt Master host, but encountering issues when running it as a non-root user. The script works fine under the root user. My non-root user's Python environment is set up with pyenv and Salt was installed via pip in this virtual environment. The Salt installation on the host machine was done using yum under the root user. Here's the script:
import salt.client
def run_shell_command(cmd: str, tgt: str = "*"):
client = salt.client.LocalClient()
res = client.cmd(tgt=tgt, fun='cmd.run', arg=[cmd])
print(res)
return res
When I run this script as a non-root user, I get the following error: "The salt master could not be contacted. Is master running?" How can I configure my setup to allow a non-root user to execute this script successfully?
How can I configure my setup to allow a non-root user to execute this script successfully?