ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

Add out of band IP option

Open Shourai opened this issue 2 years ago • 5 comments

Add oob_ip documentation

Related Issue

New Behavior

Add the option to use the out of band IP as ansible_host instead of primary_ip.

Contrast to Current Behavior

There is no option to use the out of band ip currently

Discussion: Benefits and Drawbacks

Allow users to use the new out of band ip option in their playbooks. Also the query filter has_oob_ip: True is available.

Changes to the Documentation

Proposed Release Note Entry

Add the ability to set out of band IP as ansible host.

Double Check

  • [x] I have read the comments and followed the CONTRIBUTING.md.
  • [x] I have explained my PR according to the information in the comments or in a linked issue.
  • [x] My PR targets the devel branch.

Shourai avatar Oct 05 '23 10:10 Shourai

@sc68cal, I have rebased this pull request on https://github.com/netbox-community/ansible_modules/pull/1085 However I am unsure how to write tests for this change. Any help would be appreciated!

Shourai avatar Oct 11 '23 09:10 Shourai

@Shourai you would need to add an example JSON response from Netbox for a device, that has the out of band IP attribute set, and then have an assert or equivalent check that ansible_host for the device gets set as the OOB IP instead of the primary_ip

Take a look at the existing tests in

https://github.com/netbox-community/ansible_modules/tree/devel/tests/integration/targets/inventory-v3.6/files

sc68cal avatar Nov 09 '23 17:11 sc68cal

I have tried setting up a development environment for netbox. The netbox enviroment works fine and pre-populating netbox also works fine.

However when I try to run ansible-test integration -v --color --coverage --python 3.11 inventory-v3.6 or any other inventory version for that matter it throws errors.

+ ./compare_inventory_json.py ./files/test-inventory-options.json /home/canary/worksflow_netbox/ansible_collections/netbox/netbox/tests/output/.tmp/output_dir/test-inventory-options.json
Traceback (most recent call last):
  File "/home/<user>/worksflow_netbox/ansible_collections/netbox/netbox/tests/output/.tmp/integration/inventory-v3.6-3ie7asx5-ÅÑŚÌβŁÈ/tests/integration/targets/inventory-v3.6/./compare_inventory_json.py", line 152, in <module>
    main()
  File "/home/<user>/worksflow_netbox/ansible_collections/netbox/netbox/tests/output/.tmp/integration/inventory-v3.6-3ie7asx5-ÅÑŚÌβŁÈ/tests/integration/targets/inventory-v3.6/./compare_inventory_json.py", line 144, in main
    print(json.dumps(result, sort_keys=True, indent=4))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
          ^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 202, in encode
    chunks = list(chunks)
             ^^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 432, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.11/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/usr/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PrettyOrderedSet is not JSON serializable

This just repeats several times.

Shourai avatar Dec 14 '23 14:12 Shourai

Ok, I guess this is straight forward enough where we can just merge

sc68cal avatar Dec 18 '23 17:12 sc68cal

Thank you!

Shourai avatar Dec 21 '23 15:12 Shourai

Hello, is there anything I can do to get this merged?

Shourai avatar Apr 03 '24 08:04 Shourai