pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Possible new pattern: Combine inventory / group_data ?

Open gnat opened this issue 3 years ago • 0 comments

I've been playing with combining inventory + group_data files lately, since group_data tends to be directly associated with a group of hosts inside an inventory file. Seems to work out of the box, the only thing one has to remember is:

  • group_data must be name=value.
  • Dicts and lists are interpreted as inventory.

Seems to be a pretty decent architectural simplification for pyinfra, eliminates the need for a separate directory full of group_data.

Thoughts?

Sample (ex: pyinfra/inventory/production.py)

from inventory.__common__ import *

role = 'production'
url = ''

user_name = 'guy'
user_password = ''

workspace = f'/home/{user_name}/workspace'

ssh_user = user_name
ssh_port = 22
ssh_key = f'../keys/{role}/{role}'

hosts = [
	('10.0.0.80', {**locals()}),
	('10.0.0.81', {**locals()}),
	('10.0.0.82', {**locals()}),
]

gnat avatar Apr 08 '23 07:04 gnat