diff --git a/ironic_staging_drivers/ansible/playbooks/library/facts_wwn.py b/ironic_staging_drivers/ansible/playbooks/library/facts_wwn.py index 0db549d..71497ce 100644 --- a/ironic_staging_drivers/ansible/playbooks/library/facts_wwn.py +++ b/ironic_staging_drivers/ansible/playbooks/library/facts_wwn.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -13,36 +12,33 @@ # License for the specific language governing permissions and limitations # under the License. -try: - import pyudev - HAS_PYUDEV = True -except ImportError: - HAS_PYUDEV = False - - COLLECT_INFO = (('wwn', 'WWN'), ('serial', 'SERIAL_SHORT'), ('wwn_with_extension', 'WWN_WITH_EXTENSION'), ('wwn_vendor_extension', 'WWN_VENDOR_EXTENSION')) -def get_devices_wwn(devices): - - if not HAS_PYUDEV: - LOG.warning('Can not collect "wwn", "wwn_with_extension", ' - '"wwn_vendor_extension" and "serial" when using ' - 'root device hints because there\'s no UDEV python ' - 'binds installed') - return +# TODO(pas-ha) replace module.log with module.warn +# after we require Ansible >= 2.3 +def get_devices_wwn(devices, module): + try: + import pyudev + # NOTE(pas-ha) creating context might fail if udev is missing + context = pyudev.Context() + except ImportError: + module.log('Can not collect "wwn", "wwn_with_extension", ' + '"wwn_vendor_extension" and "serial" when using ' + 'root device hints because there\'s no UDEV python ' + 'binds installed') + return {} dev_dict = {} - context = pyudev.Context() for device in devices: name = '/dev/' + device try: udev = pyudev.Device.from_device_file(context, name) except (ValueError, EnvironmentError, pyudev.DeviceNotFoundError) as e: - LOG.warning('Device %(dev)s is inaccessible, skipping... ' - 'Error: %(error)s', {'dev': name, 'error': e}) + module.log('Device %(dev)s is inaccessible, skipping... ' + 'Error: %(error)s', {'dev': name, 'error': e}) continue dev_dict[device] = {} @@ -61,7 +57,7 @@ def main(): ) devices = module.params['devices'] - data = get_devices_wwn(devices) + data = get_devices_wwn(devices, module) module.exit_json(**data) diff --git a/ironic_staging_drivers/ansible/playbooks/library/root_hints.py b/ironic_staging_drivers/ansible/playbooks/library/root_hints.py index 3fc6569..32473eb 100644 --- a/ironic_staging_drivers/ansible/playbooks/library/root_hints.py +++ b/ironic_staging_drivers/ansible/playbooks/library/root_hints.py @@ -1,4 +1,3 @@ -#!/usr/bin/python # -*- coding: utf-8 -*- # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -74,7 +73,7 @@ def main(): devices = module.params['ansible_devices'] devices_wwn = module.params['ansible_devices_wwn'] - if devices_wwn is None: + if not devices_wwn: extra = set(hints) & EXTRA_PARAMS if extra: module.fail_json(msg='Extra hints (supported by additional ansible' diff --git a/ironic_staging_drivers/ansible/playbooks/roles/discover/tasks/roothints.yaml b/ironic_staging_drivers/ansible/playbooks/roles/discover/tasks/roothints.yaml index 03ed582..488a218 100644 --- a/ironic_staging_drivers/ansible/playbooks/roles/discover/tasks/roothints.yaml +++ b/ironic_staging_drivers/ansible/playbooks/roles/discover/tasks/roothints.yaml @@ -1,8 +1,9 @@ - name: get devices wwn facts facts_wwn: devices: "{{ ansible_devices.keys() }}" + - name: calculate root hint root_hints: root_device_hints: "{{ ironic.root_device_hints }}" ansible_devices: "{{ ansible_devices }}" - ansible_devices_wwn: "{{ devices_wwn | default(None) }}" + ansible_devices_wwn: "{{ devices_wwn | default({}) }}"