You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe
When using pyinfra I generally write two kinds of scripts:
Small and modular deployments that can do specific operations, and
Larger more complete deployments that are composed of multiple scripts from (1) using pyinfra.local.include.
When running the scripts from (1) I'll often get prompted multiple times for the same credentials for decrypting secrets needed in the process of deployment by the scripts from (1) using getpass.getpass or similar. A more concrete example would be a script that deploys a web app which is made of three smaller modules:
A script to create database users and provision grants to those users needs a password to decrypt the database's root user password,
A script to restart the web app's systemd service and provision database credentials which need a password to decrypt those credentials, and
A script to write the config for and restart a caddy webserver to proxy the web app.
A larger script would execute (1), (2), and (3) in order and prompt for the same password twice in (1) and (2).
Describe the solution you'd like
My solution to this would be extending pyinfra.local.include's API to be:
Where the data parameter (or whatever a better name would be) would contain variables that could be passed to the script being executed. There is already some data being passed to the executed script in pyinfra_cli.util.exec_file, could just pass the user provided data along in a __pyinfra__ attribute (in pyinfra_cli/util.py):
# Create some base attributes for our "module"data= {"__file__": filename, "__pyinfra__": data}
# Execute the code with locals/globals going into the dict abovetry:
exec(PYTHON_CODES[filename], data)
And could provide a user accessor via a new pyinfra.local.get_variable:
And the __pyinfra__ name spacing is to keep the scope in the files mostly clean and provides a space for other work like #828. I haven't thought this all the way through so may be overlooking an obvious issue. I'm happy to work on this when I get free time to do so, mostly looking to see if there's interest, if not then there's no need to add extra features for one user.
The text was updated successfully, but these errors were encountered:
So the local.include function is already calling host.deploy under the hood (link) which already supports passing data, so this should be a pretty quick change.
Is your feature request related to a problem? Please describe
When using pyinfra I generally write two kinds of scripts:
pyinfra.local.include
.When running the scripts from (1) I'll often get prompted multiple times for the same credentials for decrypting secrets needed in the process of deployment by the scripts from (1) using
getpass.getpass
or similar. A more concrete example would be a script that deploys a web app which is made of three smaller modules:A larger script would execute (1), (2), and (3) in order and prompt for the same password twice in (1) and (2).
Describe the solution you'd like
My solution to this would be extending
pyinfra.local.include
's API to be:Where the
data
parameter (or whatever a better name would be) would contain variables that could be passed to the script being executed. There is already some data being passed to the executed script inpyinfra_cli.util.exec_file
, could just pass the user provided data along in a__pyinfra__
attribute (inpyinfra_cli/util.py
):And could provide a user accessor via a new
pyinfra.local.get_variable
:And the
__pyinfra__
name spacing is to keep the scope in the files mostly clean and provides a space for other work like #828. I haven't thought this all the way through so may be overlooking an obvious issue. I'm happy to work on this when I get free time to do so, mostly looking to see if there's interest, if not then there's no need to add extra features for one user.The text was updated successfully, but these errors were encountered: