I have done this before but this program is a bit different,
from io import StringIO
import yaml
import sys
data ='''
asdhklf
SAKDLALKSJDH
rfsudyf48
CBAKJHDSKJAH
'''
fh = StringIO(data)
data = {} # start a new dictionary
for index, line in enumerate(fh): # iterate by-line
host = line.strip() # do any needed validation here
data[host] = {
"nodename": host,
"hostname": f"{host}.northamerica.net",
"username": "rundeck",
"tags": '`rundeck`',
}
yaml.dump(data, sys.stdout)
The issue is that when I make it read from a file it always errors out.
I want to make it so that instead of having to copy and paste into the program under the data = ''' it will automatically take the data from a file path you give it.