Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace function fail inside a foreach_create_dict #5

Open
ronnyaa opened this issue Jan 1, 2023 · 0 comments
Open

replace function fail inside a foreach_create_dict #5

ronnyaa opened this issue Jan 1, 2023 · 0 comments

Comments

@ronnyaa
Copy link

ronnyaa commented Jan 1, 2023

replace function fail inside a foreach_create_dict.

the error ValueError: key #2 '{'__function': 'replace', 'value': 'mode' not found in data seem to indicate it is looking for mode and not mode.value ?

I also wonder how to do multiple replacements on the same value. eg
if netbox have mode.value, and it can be tagged or access (or unset) and I need to output portmode: as trunk, or untagged, or perhaps omit the whole portmode: if unset? but that is a bit unrelated to this error message.

~/nb2an$ cat sample.yml 
test1:
  __function: foreach_create_dict
  array: interfaces
  keyname: display
  structure:
    admin: enabled
    portmode_orig: mode.value
    portmode:
      __function: replace
      value: mode.value
      search: tagged
      replacement: trunk

test2:
  test2: device_type.manufacturer.display
~/nb2an$ nb-update-ansible  --log-level debug  -c sample.yml
DEBUG     :     loading config from /home/test/.nb2an
DEBUG     :     loading config from /home/test/.nb2an
DEBUG     :     fetching: https://netbox.drift.intern/api/dcim/devices/
DEBUG     :     Starting new HTTPS connection (1): netbox.drift.intern:443
DEBUG     :     https://netbox.drift.intern:443 "GET /api/dcim/devices/ HTTP/1.1" 200 17605
DEBUG     :     fetching: https://netbox.drift.intern/api/dcim/interfaces/?limit=100000000
DEBUG     :     Starting new HTTPS connection (1): netbox.drift.intern:443
DEBUG     :     https://netbox.drift.intern:443 "GET /api/dcim/interfaces/?limit=100000000 HTTP/1.1" 200 571362
DEBUG     :     fetching: https://netbox.drift.intern/api/ipam/ip-addresses/?family=4
DEBUG     :     Starting new HTTPS connection (1): netbox.drift.intern:443
DEBUG     :     https://netbox.drift.intern:443 "GET /api/ipam/ip-addresses/?family=4 HTTP/1.1" 200 52
DEBUG     :     fetching: https://netbox.drift.intern/api/ipam/ip-addresses/?family=6
DEBUG     :     Starting new HTTPS connection (1): netbox.drift.intern:443
DEBUG     :     https://netbox.drift.intern:443 "GET /api/ipam/ip-addresses/?family=6 HTTP/1.1" 200 52
DEBUG     :     returning cached: https://netbox.drift.intern/api/dcim/devices/
DEBUG     :     fetching: https://netbox.drift.intern/api/dcim/power-outlets/
DEBUG     :     Starting new HTTPS connection (1): netbox.drift.intern:443
DEBUG     :     https://netbox.drift.intern:443 "GET /api/dcim/power-outlets/ HTTP/1.1" 200 52
DEBUG     :     fetching: https://netbox.drift.intern/api/dcim/power-ports/
DEBUG     :     Starting new HTTPS connection (1): netbox.drift.intern:443
DEBUG     :     https://netbox.drift.intern:443 "GET /api/dcim/power-ports/ HTTP/1.1" 200 15498
DEBUG     :     starting: a2-l1.drift.intern
INFO      :     modifying /home/test/nb2an/host_vars/a2-l1.drift.intern.yml
DEBUG     :     looking for device a2-l1.drift.intern by name
DEBUG     :     returning cached: https://netbox.drift.intern/api/dcim/power-outlets/
DEBUG     :     returning cached: https://netbox.drift.intern/api/dcim/power-ports/
ERROR     :     failed to call function foreach_create_dict for item test1
Traceback (most recent call last):
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/tools/update_ansible.py", line 94, in process_changes
    value = fn(dn, yaml_struct, changes[item], item)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/plugins/update_ansible.py", line 57, in fn_foreach_create_dict
    fn_foreach_augment_dict(dn, yaml_struct, definition, item)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/plugins/update_ansible.py", line 17, in _wrap
    return function(*args, **kwargs)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/plugins/update_ansible.py", line 78, in fn_foreach_augment_dict
    value = dn.get(path)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/dotnest.py", line 31, in get
    raise ValueError(f"key #{n} '{k}' not found in data")
ValueError: key #2 '{'__function': 'replace', 'value': 'mode' not found in data

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/test/.local/bin/nb-update-ansible", line 8, in <module>
    sys.exit(main())
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/tools/update_ansible.py", line 184, in main
    process_devices(nb, ansible_directory, racks=args.racks, changes=changes)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/tools/update_ansible.py", line 159, in process_devices
    process_host(nb, name, device_yaml, changes=changes)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/tools/update_ansible.py", line 140, in process_host
    process_changes(changes, yaml_struct, nb_data)
  File "/home/test/.local/lib/python3.9/site-packages/nb2an/tools/update_ansible.py", line 97, in process_changes
    errors = traceback.format_exception(exp)
TypeError: format_exception() missing 2 required positional arguments: 'value' and 'tb'

Best Regards
Ronny Aasen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant