I am trying to use the Ansible gather_facts data from a Linux host as input:
"ansible_fibre_channel_wwn": [
"1000e0071bd4d0ed",
"10009440c90f9d85",
"1000e0071bce95f3",
"1000e0071bce95f2",
"1000e0071bd4d0ec",
"10009440c90f9d84"
],
And would like to create a dictionary using the above list items for dictionary values of a new "wwpn" key:
fc_initiators: [
{wwpn: '10:00:e0:07:1b:d4:d0:ed'},
{wwpn: '10:00:94:40:c9:0f:9d:85'},
{wwpn: '10:00:e0:07:1b:ce:95:f3'},
{wwpn: '10:00:e0:07:1b:ce:95:f2'},
{wwpn: '10:00:e0:07:1b:d4:d0:ec'},
{wwpn: '10:00:94:40:c9:0f:9d:84'}
]
This regex seems sufficient for converting the initial list items into colonized WWPN:
"{{ ansible_fibre_channel_wwn |
map('regex_replace', '^(..)(..)(..)(..)(..)(..)(..)(..)$', '\\1:\\2:\\3:\\4:\\5:\\6:\\7:\\8')|list }}"
I'm not sure where to start with the list->dictionary conversion though. Any help is much appreciated.
Thanks!