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

Add descriptive error message to Linode inventory plugin file checkin… #8133

Merged
merged 3 commits into from
Mar 24, 2024

Conversation

GideonStowell
Copy link
Contributor

@GideonStowell GideonStowell commented Mar 23, 2024

SUMMARY

#6279 Raised issue with the linode inventory plugin validation function not providing a useful error message when it fails. Other inventory plugins do have useful error message on failure. This PR aligns the linode inventory plugin with other plugins.

Fixes #6279

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

community.general.plugins.inventory.linode

ADDITIONAL INFORMATION

Before:

$ ansible-inventory -i foo.yml --list -vvv
ansible-inventory [core 2.16.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/gideons/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/gideons/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/gideons/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/gideons/.local/bin/ansible-inventory
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/gideons/foo.yml as it did not pass its verify_file() method
script declined parsing /home/gideons/foo.yml as it did not pass its verify_file() method
redirecting (type: inventory) ansible.builtin.linode to community.general.linode
toml declined parsing /home/gideons/foo.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /home/gideons/foo.yml with auto plugin: inventory source
'/home/gideons/foo.yml' could not be verified by inventory plugin 'linode'
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/plugins/inventory/auto.py", line 56, in parse
    raise AnsibleParserError("inventory source '{0}' could not be verified by inventory plugin '{1}'".format(path, plugin_name))
[WARNING]:  * Failed to parse /home/gideons/foo.yml with yaml plugin: Plugin configuration YAML file,
not YAML inventory
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/plugins/inventory/yaml.py", line 114, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]:  * Failed to parse /home/gideons/foo.yml with ini plugin: Invalid host pattern 'plugin:'
supplied, ending in ':' is not allowed, this character is reserved to provide a port.
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/plugins/inventory/ini.py", line 138, in parse
    raise AnsibleParserError(e)
[WARNING]: Unable to parse /home/gideons/foo.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

After:

$ ANSIBLE_INVENTORY_PLUGINS=~/ansible-collections.community.general/ansible_collections/community/general/plugins/inventory ansible-inventory -i foo.yml --list -vvv
ansible-inventory [core 2.16.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/gideons/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/gideons/.local/lib/python3.10/site-packages/ansible
  ansible collection location = /home/gideons/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/gideons/.local/bin/ansible-inventory
  python version = 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/gideons/foo.yml as it did not pass its verify_file() method
script declined parsing /home/gideons/foo.yml as it did not pass its verify_file() method
Inventory source not ending in "linode.yaml" or "linode.yml"
toml declined parsing /home/gideons/foo.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /home/gideons/foo.yml with auto plugin: inventory source
'/home/gideons/foo.yml' could not be verified by inventory plugin 'linode'
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/plugins/inventory/auto.py", line 56, in parse
    raise AnsibleParserError("inventory source '{0}' could not be verified by inventory plugin '{1}'".format(path, plugin_name))
[WARNING]:  * Failed to parse /home/gideons/foo.yml with yaml plugin: Plugin configuration YAML file,
not YAML inventory
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/plugins/inventory/yaml.py", line 114, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]:  * Failed to parse /home/gideons/foo.yml with ini plugin: Invalid host pattern 'plugin:'
supplied, ending in ':' is not allowed, this character is reserved to provide a port.
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/home/gideons/.local/lib/python3.10/site-packages/ansible/plugins/inventory/ini.py", line 138, in parse
    raise AnsibleParserError(e)
[WARNING]: Unable to parse /home/gideons/foo.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added WIP Work in progress bug This issue/PR relates to a bug cloud inventory inventory plugin new_contributor Help guide this first time contributor plugins plugin (any type) tests tests traceback unit tests/unit labels Mar 23, 2024
@displague
Copy link

displague commented Mar 24, 2024

shipit

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-7 backport-8 Automatically create a backport for the stable-8 branch labels Mar 24, 2024
@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Mar 24, 2024
@felixfontein felixfontein merged commit b389f86 into ansible-collections:main Mar 24, 2024
133 checks passed
Copy link

patchback bot commented Mar 24, 2024

Backport to stable-7: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-7/b389f8637f3bcc4f794c708379c9e65ff4f26f6f/pr-8133

Backported as #8143

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Mar 24, 2024
#8133)

* Add descriptive error message to Linode inventory plugin file checking, tests

* add changelog fragment

* Adjust changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b389f86)
Copy link

patchback bot commented Mar 24, 2024

Backport to stable-8: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-8/b389f8637f3bcc4f794c708379c9e65ff4f26f6f/pr-8133

Backported as #8144

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Mar 24, 2024
#8133)

* Add descriptive error message to Linode inventory plugin file checking, tests

* add changelog fragment

* Adjust changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b389f86)
@felixfontein
Copy link
Collaborator

@GideonStowell thanks for your contribution!
@displague thanks for reviewing!

felixfontein pushed a commit that referenced this pull request Mar 24, 2024
…to Linode inventory plugin file checkin… (#8143)

Add descriptive error message to Linode inventory plugin file checkin… (#8133)

* Add descriptive error message to Linode inventory plugin file checking, tests

* add changelog fragment

* Adjust changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b389f86)

Co-authored-by: Gideon <soccerman.gid@gmail.com>
felixfontein pushed a commit that referenced this pull request Mar 24, 2024
…to Linode inventory plugin file checkin… (#8144)

Add descriptive error message to Linode inventory plugin file checkin… (#8133)

* Add descriptive error message to Linode inventory plugin file checking, tests

* add changelog fragment

* Adjust changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit b389f86)

Co-authored-by: Gideon <soccerman.gid@gmail.com>
Massl123 pushed a commit to Massl123/community.general that referenced this pull request Feb 7, 2025
ansible-collections#8133)

* Add descriptive error message to Linode inventory plugin file checking, tests

* add changelog fragment

* Adjust changelog fragment.

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8 Automatically create a backport for the stable-8 branch bug This issue/PR relates to a bug cloud has_issue inventory inventory plugin new_contributor Help guide this first time contributor plugins plugin (any type) tests tests traceback unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

community.general.linode - document requirement that inventory file end in <something>linode.yml
4 participants