mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-01 12:40:22 -07:00
* Fix #9538 Inventory iocage fails when DHCP is enbled. * Add changelog fragment 9539-iocage-inventory-dhcp.yml * Keep iocage_ip4 a string. * Rename the variable iocage_ip4 to iocage_ip4_dict in _parse_ip4. * Update the changelog fragment. * Rename _parse_ip4 parameter ip4_addr to ip4. * Fix changelog frangment present tense. * If IP is not available set iocage_ip4='-' instead of the empty string. * Update changelogs/fragments/9539-iocage-inventory-dhcp.yml Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
d325cfc343
commit
94d5256adb
28 changed files with 243 additions and 17 deletions
|
@ -131,9 +131,27 @@ display = Display()
|
|||
|
||||
|
||||
def _parse_ip4(ip4):
|
||||
if ip4 == '-':
|
||||
return ip4
|
||||
return re.split('\\||/', ip4)[1]
|
||||
''' Return dictionary iocage_ip4_dict. default = {ip4: [], msg: ''}.
|
||||
If item matches ifc|IP or ifc|CIDR parse ifc, ip, and mask.
|
||||
Otherwise, append item to msg.
|
||||
'''
|
||||
|
||||
iocage_ip4_dict = {}
|
||||
iocage_ip4_dict['ip4'] = []
|
||||
iocage_ip4_dict['msg'] = ''
|
||||
|
||||
items = ip4.split(',')
|
||||
for item in items:
|
||||
if re.match('^\\w+\\|(?:\\d{1,3}\\.){3}\\d{1,3}.*$', item):
|
||||
i = re.split('\\||/', item)
|
||||
if len(i) == 3:
|
||||
iocage_ip4_dict['ip4'].append({'ifc': i[0], 'ip': i[1], 'mask': i[2]})
|
||||
else:
|
||||
iocage_ip4_dict['ip4'].append({'ifc': i[0], 'ip': i[1], 'mask': '-'})
|
||||
else:
|
||||
iocage_ip4_dict['msg'] += item
|
||||
|
||||
return iocage_ip4_dict
|
||||
|
||||
|
||||
class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||
|
@ -194,7 +212,6 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
|
||||
cmd_list = cmd.copy()
|
||||
cmd_list.append('list')
|
||||
cmd_list.append('--header')
|
||||
cmd_list.append('--long')
|
||||
try:
|
||||
p = Popen(cmd_list, stdout=PIPE, stderr=PIPE, env=my_env)
|
||||
|
@ -239,16 +256,26 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
return results
|
||||
|
||||
def get_jails(self, t_stdout, results):
|
||||
jails = [x.split() for x in t_stdout.splitlines()]
|
||||
for jail in jails:
|
||||
lines = t_stdout.splitlines()
|
||||
if len(lines) < 5:
|
||||
return
|
||||
indices = [i for i, val in enumerate(lines[1]) if val == '|']
|
||||
for line in lines[3::2]:
|
||||
jail = [line[i + 1:j].strip() for i, j in zip(indices[:-1], indices[1:])]
|
||||
iocage_name = jail[1]
|
||||
iocage_ip4_dict = _parse_ip4(jail[6])
|
||||
if iocage_ip4_dict['ip4']:
|
||||
iocage_ip4 = ','.join([d['ip'] for d in iocage_ip4_dict['ip4']])
|
||||
else:
|
||||
iocage_ip4 = '-'
|
||||
results['_meta']['hostvars'][iocage_name] = {}
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_jid'] = jail[0]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_boot'] = jail[2]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_state'] = jail[3]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_type'] = jail[4]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_release'] = jail[5]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_ip4'] = _parse_ip4(jail[6])
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_ip4_dict'] = iocage_ip4_dict
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_ip4'] = iocage_ip4
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_ip6'] = jail[7]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_template'] = jail[8]
|
||||
results['_meta']['hostvars'][iocage_name]['iocage_basejail'] = jail[9]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue