1import yaml
2
3fname = "some.yaml"
4
5stream = open(fname, 'r')
6data = yaml.load(stream)
7
8data['instances'][0]['host'] = '1.2.3.4'
9data['instances'][0]['username'] = 'Username'
10data['instances'][0]['password'] = 'Password'
11
12with open(fname, 'w') as yaml_file:
13 yaml_file.write( yaml.dump(data, default_flow_style=False))
14