Skip to content

Commit

Permalink
cobbler: Properly determine cobbler_ipv4/6_address
Browse files Browse the repository at this point in the history
  • Loading branch information
opoplawski committed Jul 13, 2023
1 parent 065ce3a commit f7440b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6925-cobbler-inventory-bugfix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- cobbler inventory plugin - fix calculation of cobbler_ipv4/6_address (https://github.com/ansible-collections/community.general/pull/6925).
20 changes: 13 additions & 7 deletions plugins/inventory/cobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,22 @@ def parse(self, inventory, loader, path, cache=True):

# Add host variables
ip_address = None
ip_address_first = None
ipv6_address = None
ipv6_address_first = None
for iname, ivalue in interfaces.items():
# Set to first interface or management interface if defined or hostname matches dns_name
if ivalue['ip_address'] != "":
if ip_address is None:
ip_address = ivalue['ip_address']
elif ivalue['management']:
if ip_address_first is None:
ip_address_first = ivalue['ip_address']
if ivalue['management']:
ip_address = ivalue['ip_address']
elif ivalue['dns_name'] == hostname and ip_address is None:
ip_address = ivalue['ip_address']
if ivalue['ipv6_address'] != "":
if ipv6_address is None:
ipv6_address = ivalue['ipv6_address']
elif ivalue['management']:
if ipv6_address_first is None:
ipv6_address_first = ivalue['ipv6_address']
if ivalue['management']:
ipv6_address = ivalue['ipv6_address']
elif ivalue['dns_name'] == hostname and ipv6_address is None:
ipv6_address = ivalue['ipv6_address']
Expand All @@ -333,9 +335,13 @@ def parse(self, inventory, loader, path, cache=True):
if ivalue['ipv6_address'] != "":
ip_addresses[ivalue['dns_name']] = ivalue['ipv6_address']

# Add ip_address to host if defined
# Add ip_address to host if defined, use first if no management or matched dns_name
if ip_address is None and ip_address_first is not None:
ip_address = ip_address_first
if ip_address is not None:
self.inventory.set_variable(hostname, 'cobbler_ipv4_address', ip_address)
if ipv6_address is None and ipv6_address_first is not None:
ipv6_address = ipv6_address_first
if ipv6_address is not None:
self.inventory.set_variable(hostname, 'cobbler_ipv6_address', ipv6_address)

Expand Down

0 comments on commit f7440b0

Please sign in to comment.