In [1]: import yaml
In [2]: ymlsample="""
...: branch1:
...: name: branch1
...: ip: 1.2.3.4
...: ASN: 65101
...: type: cisco
...: auth:
...: username: username
...: password: password
...: branch2:
...: name: branch2
...: ip: 2.3.4.5
...: ASN: 65102
...: type: juniper
...: auth:
...: username: username
...: password: password
...: """
In [3]: hosts = yaml.safe_load(ymlsample)
In [4]: hosts
Out[4]:
{'branch1': {'name': 'branch1',
'ip': '1.2.3.4',
'ASN': 65101,
'type': 'cisco',
'auth': {'username': 'username', 'password': 'password'}},
'branch2': {'name': 'branch2',
'ip': '2.3.4.5',
'ASN': 65102,
'type': 'juniper',
'auth': {'username': 'username', 'password': 'password'}}}