Is it possible to access build-version in prepare.py config script somehow?
Yes. To obtain your argument from CLI, the argument must be declared in the prepare.py script(or possibly anywhere data/group_data exists) and accessed as host.data.argument_name. See sample below:
from pyinfra import host
from pyinfra.api import deploy
# the argument you want
build_version: str = ""
# more arguments with defaults
DEFAULTS = {"foo": None, "bar": ""}
@deploy("Foobar", data_defaults=DEFAULTS)
def samplex():
print(
f"\r\n\t{'='*9} RECEIVED ARGUMENTS FROM TERMINAL -> {host.data.build_version} {'='*9}\n")
print(
f"\r\n\t{'='*9} RECEIVED EXTRAS FROM TERMINAL ->{host.data.foo} :: {host.data.bar} {'='*9}\n")
From CLI you can call the function as:
pyinfra inventory.py testbed.samplex --data build_version=v1.0 --data foo=baz --data bar=barfoo -y