Question: Can PyInfra work with temporary files? #1554
-
|
Hi, After attending the FOSDEM 2026 talk about PyInfra I decided to start playing around and see how to provision my servers with PyInfra. Normally, I manage the services on my remote servers with Docker Compose. There is a operation module for Docker, but not for Docker Compose, so I took the following approach:
It works perfectly if the Either I use a context manager for the temporary file, or I create it and delete at the end of my Python file, the execution fails because by the time is read to be uploaded, it does not exist anymore. Probably, this is because the plan is done before executed. Given that use case, is it possible to create temporal files to be uploaded to the remote server? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I'll, partially, answer myself: I do not know if you can work with temporal files, but you can make use of the import io
env_file_content = """\
VAR_1=foo
VAR_2=bar
"""
files.put(
src=io.StringIO(env_file_content),
dest="/path/to/.env",
)This will put/upload the content of |
Beta Was this translation helpful? Give feedback.
I'll, partially, answer myself: I do not know if you can work with temporal files, but you can make use of the
iomodule; here is a snippet:This will put/upload the content of
env_file_contentto a file on the server. Of course, you can do variable interpolation, make use of Pydantic Settings, environment variables, etc.