pyinfra
pyinfra copied to clipboard
Global or per-operation class env vars
Is your feature request related to a problem? Please describe
Not sure if this is actually a feature that would make sense to add, but this is the issue that I am dealing with:
The command brew update
used by the brew.update()
operation automatically stashes any local changes that have been made to brew recipes (one might do this if you need to patch a brew recipe to get at a specific version that doesn't have an @version
). The way to get around this is to set the environment var HOMEBREW_DEVELOPER
when running the brew commands. In order to do this via pyinfra
, I need to pass that in via the env
param to each brew.*
operation, which is tedious and can be error prone (since brew
will just stash the modifications and carry on as though nothing out of the ordinary happened).
Describe the solution you'd like
I'd like a way to specify a set of environment vars that will be passed automatically to all invocations of a particular operation class, possibly as some sort of special group_data
key?
Maybe, something like this:
pyinfra_operations_brew = {
"HOMBREW_DEVELOPER": 1,
}
There is probably a more elegant solution, but that is the gist of what I am hoping for.
One option here is to use the ENV
config var which would apply to all operations within a deploy; ie:
# config.py
ENV = {
"HOMBREW_DEVELOPER": 1,
}
# or, new style recommended in v1.5+
from pyinfra import config
config.ENV = {
"HOMBREW_DEVELOPER": 1,
}
I believe this would provide a suitable solution? Setting environment variables for a given set of operations would be a bit confusing, I think, vs. this global approach.