I have source of truth stored in yaml file sot-inventory.yaml
- Hostname: NY-SW1
IP mgmt address: 10.1.1.1
OS: IOS
Operational status: Install
Role of work: Switch
Site: New_York
- Hostname: MI-SW1
IP mgmt address: 11.1.1.1
OS: NX-OS
Operational status: Install
Role of work: Switch
Site: Maiami
- Hostname: PA-SW1
IP mgmt address: 12.1.1.1
OS: Arista
Operational status: Install
Role of work: Witch
Site: Paris
I would like to get yaml ansible hosts inventory from file above with python script like this:
hosts.yaml
---
new_york:
hosts:
ny-sw1:
ansible_host: 10.1.1.1
os: ios
'role of work': switch
maiami:
hosts:
mi-sw1:
ansible_host: 11.1.1.1
os: nxos
'role of work': switch
paris:
hosts:
pa-sw1:
ansible_host: 12.1.1.1
os: arista
'role of work': switch
Could someone give an advice - which python structure or sample of scrypt may help to automate this staff?