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

Added services in hostvars #47919

Closed
wants to merge 5 commits into from
Closed

Added services in hostvars #47919

wants to merge 5 commits into from

Conversation

ollybee
Copy link

@ollybee ollybee commented Nov 1, 2018

SUMMARY

services addition in hostvars in netbox dynamic inventory
Fixed #47918

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

netbox-services in hostvars in netbox dynamic inventory

ANSIBLE VERSION
ansible 2.7.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/oliver/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
ADDITIONAL INFORMATION

Before change

ansible-inventory 2.7.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/monitoring/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-inventory
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
/home/monitoring/ansible/netbox_inventory.yml did not meet host_list requirements, check plugin documentation if this is unexpected
/home/monitoring/ansible/netbox_inventory.yml did not meet virtualbox requirements, check plugin documentation if this is unexpected
Fetching: https://netboxdev.hyperslice.net/api/dcim/sites/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/regions/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/tenancy/tenants/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/racks/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/device-roles/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/device-types/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/manufacturers/?limit=0
Fetching: https://netboxdev.hyperslice.net//api/dcim/devices/?limit=0&name=someserver
Fetching: https://netboxdev.hyperslice.net//api/virtualization/virtual-machines/?limit=0&name=someserver
Parsed /home/monitoring/ansible/netbox_inventory.yml inventory source with netbox plugin
{
    "config_context": [
        {}
    ],
    "device_roles": [
        "Dummy server"
    ],
    "device_types": [
        "Dummy"
    ],
    "manufacturers": [
        "Dummy"
    ],
    "sites": [
        "Dummy site"
    ]
}

After Change

ansible-inventory -vvv -i ./netbox_inventory.yml --host someserver
ansible-inventory 2.7.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/monitoring/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-inventory
  python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Using /etc/ansible/ansible.cfg as config file
/home/monitoring/ansible/netbox_inventory.yml did not meet host_list requirements, check plugin documentation if this is unexpected
/home/monitoring/ansible/netbox_inventory.yml did not meet virtualbox requirements, check plugin documentation if this is unexpected
Fetching: https://netboxdev.hyperslice.net/api/dcim/sites/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/regions/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/tenancy/tenants/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/racks/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/device-roles/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/device-types/?limit=0
Fetching: https://netboxdev.hyperslice.net/api/dcim/manufacturers/?limit=0
Fetching: https://netboxdev.hyperslice.net//api/dcim/devices/?limit=0&name=someserver
Fetching: https://netboxdev.hyperslice.net//api/virtualization/virtual-machines/?limit=0&name=someserver
Parsed /home/monitoring/ansible/netbox_inventory.yml inventory source with netbox plugin
{
    "config_context": [
        {}
    ],
    "device_roles": [
        "Dummy server"
    ],
    "device_types": [
        "Dummy"
    ],
    "manufacturers": [
        "Dummy"
    ],
    "services": [
        [
            {
                "created": "2018-11-01",
                "custom_fields": {
                    "key_text": null
                },
                "description": "",
                "device": {
                    "display_name": "someserver",
                    "id": 13084,
                    "name": "someserver",
                    "url": "https://netboxdev.hyperslice.net/api/dcim/devices/13084/"
                },
                "id": 28,
                "ipaddresses": [
                    {
                        "address": "10.2.1.1/24",
                        "family": 4,
                        "id": 145531,
                        "url": "https://netboxdev.hyperslice.net/api/ipam/ip-addresses/145531/"
                    }
                ],
                "last_updated": "2018-11-01T12:13:39.326592Z",
                "name": "SSH",
                "port": 22,
                "protocol": {
                    "label": "TCP",
                    "value": 6
                },
                "virtual_machine": null
            },
            {
                "created": "2018-11-01",
                "custom_fields": {
                    "key_text": null
                },
                "description": "",
                "device": {
                    "display_name": "someserver",
                    "id": 13084,
                    "name": "someserver",
                    "url": "https://netboxdev/api/dcim/devices/13084/"
                },
                "id": 29,
                "ipaddresses": [],
                "last_updated": "2018-11-01T11:59:18.855776Z",
                "name": "awebsite.org",
                "port": 443,
                "protocol": {
                    "label": "TCP",
                    "value": 6
                },
                "virtual_machine": null
            },
            {
                "created": "2018-11-01",
                "custom_fields": {
                    "key_text": null
                },
                "description": "",
                "device": {
                    "display_name": "someserver",
                    "id": 13084,
                    "name": "someserver",
                    "url": "https://netboxdev/api/dcim/devices/13084/"
                },
                "id": 30,
                "ipaddresses": [],
                "last_updated": "2018-11-01T11:59:32.669569Z",
                "name": "anothersite.net",
                "port": 443,
                "protocol": {
                    "label": "TCP",
                    "value": 6
                },
                "virtual_machine": null
            },
            {
                "created": "2018-11-01",
                "custom_fields": {
                    "key_text": null
                },
                "description": "",
                "device": {
                    "display_name": "someserver",
                    "id": 13084,
                    "name": "someserver",
                    "url": "https://netboxdev/api/dcim/devices/13084/"
                },
                "id": 31,
                "ipaddresses": [],
                "last_updated": "2018-11-01T11:59:54.599007Z",
                "name": "arbitaryservice",
                "port": 5544,
                "protocol": {
                    "label": "UDP",
                    "value": 17
                },
                "virtual_machine": null
            }
        ]
    ],
    "sites": [
        "Dummy site"
    ]
}

@ollybee ollybee changed the title Update netbox.py Added services in hostvars Nov 1, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 1, 2018

Hi @ollybee, thank you for submitting this pull-request!

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 1, 2018

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 community_review In order to be merged, this PR must follow the community review workflow. feature This issue/PR relates to a feature request. inventory Inventory category needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. support:community This issue/PR relates to code supported by the Ansible community. labels Nov 1, 2018
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Nov 1, 2018
@FragmentedPacket
Copy link
Contributor

@ollybee I would most likely remove the [] around the device_lookup["results"] as it's already a list so we wouldn't have to hit a 0 index to get the necessary information.

Also, you may want to sync up your file with what is in devel for the def refresh_url as it contains some previous bug fixes and we don't regress.

Other than those, it worked as intended:

            "test51": {
                "config_context": [
                    {
                        "test": "test1"
                    }
                ], 
                "device_roles": [
                    "Console Server"
                ], 
                "device_types": [
                    "test"
                ], 
                "manufacturers": [
                    "Cisco"
                ], 
                "services": [
                    {
                        "created": "2018-11-02", 
                        "custom_fields": {}, 
                        "description": "", 
                        "device": {
                            "display_name": "test51", 
                            "id": 74, 
                            "name": "test51", 
                            "url": "http://netbox-demo.org/api/dcim/devices/74/"
                        }, 
                        "id": 1, 
                        "ipaddresses": [], 
                        "last_updated": "2018-11-02T02:00:43.567445Z", 
                        "name": "Jalepenos", 
                        "port": 144, 
                        "protocol": {
                            "label": "TCP", 
                            "value": 6
                        }, 
                        "virtual_machine": null
                    }, 
                    {
                        "created": "2018-11-02", 
                        "custom_fields": {}, 
                        "description": "", 
                        "device": {
                            "display_name": "test51", 
                            "id": 74, 
                            "name": "test51", 
                            "url": "http://netbox-demo.org/api/dcim/devices/74/"
                        }, 
                        "id": 2, 
                        "ipaddresses": [], 
                        "last_updated": "2018-11-02T02:01:45.851961Z", 
                        "name": "Pineapples", 
                        "port": 1412, 
                        "protocol": {
                            "label": "UDP", 
                            "value": 17
                        }, 
                        "virtual_machine": null
                    }
                ], 
                "sites": [
                    "test"
                ]
            }

@FragmentedPacket
Copy link
Contributor

LGTM

lib/ansible/plugins/inventory/netbox.py Outdated Show resolved Hide resolved
lib/ansible/plugins/inventory/netbox.py Outdated Show resolved Hide resolved
@ansibot
Copy link
Contributor

ansibot commented Nov 2, 2018

@ollybee This PR contains @ mentions in at least one commit message. Those mentions can cause cascading notifications through GitHub and need to be removed. Please squash or amend your commits to remove the mentions.

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Nov 2, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 2, 2018

The test ansible-test sanity --test pylint [explain] failed with 2 errors:

lib/ansible/plugins/inventory/netbox.py:255:0: trailing-whitespace Trailing whitespace
lib/ansible/plugins/inventory/netbox.py:263:0: trailing-whitespace Trailing whitespace

The test ansible-test sanity --test pep8 [explain] failed with 12 errors:

lib/ansible/plugins/inventory/netbox.py:201:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:201:1: W191 indentation contains tabs
lib/ansible/plugins/inventory/netbox.py:201:4: E131 continuation line unaligned for hanging indent
lib/ansible/plugins/inventory/netbox.py:202:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:255:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:255:1: W191 indentation contains tabs
lib/ansible/plugins/inventory/netbox.py:255:1: W293 blank line contains whitespace
lib/ansible/plugins/inventory/netbox.py:256:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:263:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:263:1: W191 indentation contains tabs
lib/ansible/plugins/inventory/netbox.py:263:1: W293 blank line contains whitespace
lib/ansible/plugins/inventory/netbox.py:264:1: E101 indentation contains mixed spaces and tabs

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Nov 2, 2018
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Nov 2, 2018
@mattclay mattclay added the ci_verified Changes made in this PR are causing tests to fail. label Nov 5, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 5, 2018

The test ansible-test sanity --test pylint [explain] failed with 3 errors:

lib/ansible/plugins/inventory/netbox.py:255:0: trailing-whitespace Trailing whitespace
lib/ansible/plugins/inventory/netbox.py:263:0: trailing-whitespace Trailing whitespace
lib/ansible/plugins/inventory/netbox.py:451:0: trailing-newlines Trailing newlines

The test ansible-test sanity --test pep8 [explain] failed with 9 errors:

lib/ansible/plugins/inventory/netbox.py:255:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:255:1: W191 indentation contains tabs
lib/ansible/plugins/inventory/netbox.py:255:1: W293 blank line contains whitespace
lib/ansible/plugins/inventory/netbox.py:256:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:263:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:263:1: W191 indentation contains tabs
lib/ansible/plugins/inventory/netbox.py:263:1: W293 blank line contains whitespace
lib/ansible/plugins/inventory/netbox.py:264:1: E101 indentation contains mixed spaces and tabs
lib/ansible/plugins/inventory/netbox.py:451:1: W391 blank line at end of file

click here for bot help

@ansibot ansibot removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 6, 2018
@ansibot ansibot added the community_review In order to be merged, this PR must follow the community review workflow. label Nov 6, 2018
@FragmentedPacket
Copy link
Contributor

LGTM

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Nov 14, 2018
@gundalow
Copy link
Contributor

@FragmentedPacket
Copy link
Contributor

@ollybee Do you mind rebasing and then we can get this merged? 2.8 RC is right around the corner.

@jhanssenfavaro
Copy link

Hi Folks, I am also waiting for this commit. Its a huge improvement in the netbox plugin.. anyone aware if is it already available ? Best Regards!!!

@Akasurde
Copy link
Member

superseded by netbox-community/ansible_modules#202

@ollybee Thanks for the contribution.

@Akasurde Akasurde closed this Jul 14, 2020
@ansible ansible locked and limited conversation to collaborators Aug 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 feature This issue/PR relates to a feature request. has_issue inventory Inventory category needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

services-addition in hostvars in netbox dynamic inventory
9 participants