Open gnat opened 3 years ago
For those following this, here's one method that works, although perhaps not the most elegant or API stable:
from pyinfra_cli.util import exec_file
production = exec_file('inventories/production.py')
print(f"{production['hosts']}")
Big fan of this idea, @gnat! Will have a think about how best to implement.
Is your feature request related to a problem? Please describe. There does not seem to be an obvious way to access inventories other than the one pyinfra is currently operating on.
Would be great to be able to access the host list inside of
inventories/production.py
while running againstinventories/staging.py
for example.Useful case 1: Do fancy auto-configuration (firewalls...) easily using host information inside different inventories. Useful case 2: Can test scripts using
@local
, etc. easier.Describe the solution you'd like Be able to reach data in other inventories in some way, maybe just allow
import ..inventories.production
? Unsure what would be the best approach.Thanks!!