79115966

Date: 2024-10-22 22:50:01
Score: 1.5
Natty:
Report link

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
Reasons:
  • Blacklisted phrase (1): Is it possible to
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Is it
  • Low reputation (0.5):
Posted by: Staccato