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

The compose variable is incorrectly declared as a boolean #28

Closed
spam-n-eggs opened this issue Apr 3, 2024 Discussed in #27 · 0 comments · Fixed by #29
Closed

The compose variable is incorrectly declared as a boolean #28

spam-n-eggs opened this issue Apr 3, 2024 Discussed in #27 · 0 comments · Fixed by #29
Assignees
Labels
bug Something isn't working

Comments

@spam-n-eggs
Copy link
Contributor

Upon further investigation, it appears that the compose variable is incorrectly defined in the DOCUMENTATION block in the netbird.py inventory file. This is causing errors when people are passing in ansible mapping types.

Discussed in #27

Originally posted by ipsecguy April 3, 2024
Hi, I am using ansible core 2.16.5 on debian 12 and pulled this netbird plugin via ansible-galaxy collection install dominion_solutions.netbird

After some trouble getting it running (mostly due to me getting started with dynamic inventories) I am now getting a proper list of netbird devices out of the inventory.

Additionally, the error message about invalid characters does not seem correct, there are no curly braces in.

inventory.netbird.yml

---
plugin: dominion_solutions.netbird.netbird
api_key: nbp_*redacted*
api_url: https://api.netbird.io/api/
#netbird_connected: True
netbird_groups:
- "APU Probes"

ansible-inventory --list -i inventory.netbird.yml -vvvv

ansible-inventory [core 2.16.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-inventory
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /home/ansible/ansible/inventory.netbird.yml as it did not pass its verify_file() method
script declined parsing /home/ansible/ansible/inventory.netbird.yml as it did not pass its verify_file() method
Loading collection dominion_solutions.netbird from /home/ansible/.ansible/collections/ansible_collections/dominion_solutions/netbird
Using inventory plugin 'ansible_collections.dominion_solutions.netbird.plugins.inventory.netbird' to process inventory source '/home/ansible/ansible/inventory.netbird.yml'
Building the Netbird API Client.
Set up the Netbird API Client with the URL: https://api.netbird.io/api/
Not replacing invalid character(s) "{' '}" in group name (APU Probes)
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Parsed /home/ansible/ansible/inventory.netbird.yml inventory source with auto plugin
{
    "APU Probes": {
        "hosts": [
            "netbird2.netbird.cloud",
            "netbird3.netbird.cloud"
        ]
    },
    "All": {
        "hosts": [
            "netbird2.netbird.cloud",
            "netbird3.netbird.cloud"
        ]
    },
    "_meta": {
        "hostvars": {
            "netbird2.netbird.cloud": {
                "accessible_peers_count": 11,
                "approval_required": false,
                "city_name": "Frankfurt am Main",
                "connected": true,
                "connection_ip": "2a02:8071:50d1:6ce0:78bc:16ff:feb1:17ff",
                "country_code": "DE",
                "dns_label": "netbird2.netbird.cloud",
                "geoname_id": 2925533,
                "hostname": "vm-b117ff",
                "id": "cnr0sr3l0ubs73bek1o0",
                "ip": "100.88.192.148",
                "kernel_version": "6.1.0-18-amd64",
                "last_login": "2024-03-16T21:26:04.384004993Z",
                "last_seen": "2024-04-03T07:15:16.19041215Z",
                "login_expiration_enabled": false,
                "login_expired": false,
                "name": "netbird2",
                "os": "Debian GNU/Linux 12",
                "ssh_enabled": false,
                "ui_version": "",
                "user_id": "",
                "version": "0.26.7"
            },
            "netbird3.netbird.cloud": {
                "accessible_peers_count": 11,
                "approval_required": false,
                "city_name": "Frankfurt am Main",
                "connected": true,
                "connection_ip": "2a02:8071:50d1:6ce0:78bc:16ff:fe59:7586",
                "country_code": "DE",
                "dns_label": "netbird3.netbird.cloud",
                "geoname_id": 2925533,
                "hostname": "vm-597586",
                "id": "cnrbe53l0ubs73bek9tg",
                "ip": "100.88.155.178",
                "kernel_version": "6.1.0-18-amd64",
                "last_login": "2024-03-17T09:25:40.498995934Z",
                "last_seen": "2024-04-03T07:16:46.855499107Z",
                "login_expiration_enabled": false,
                "login_expired": false,
                "name": "netbird3",
                "os": "Debian GNU/Linux 12",
                "ssh_enabled": false,
                "ui_version": "",
                "user_id": "",
                "version": "0.26.7"
            }
        }
    },
    "all": {
        "children": [
            "ungrouped",
            "All",
            "APU Probes"
        ]
    }
}

However, when I add any compose: to add variables (I started with adding a static value)

---
plugin: dominion_solutions.netbird.netbird
api_key: nbp_*redacted*
api_url: https://api.netbird.io/api/
#netbird_connected: True
netbird_groups:
- "APU Probes"

compose:
  ansible_port: 22

However, when I add this and run

ansible-inventory --list -i inventory.netbird.yml -vvvv

ansible-inventory [core 2.16.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-inventory
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from
host_list declined parsing /home/ansible/ansible/inventory.netbird.yml as it did not pass its verify_file() method
script declined parsing /home/ansible/ansible/inventory.netbird.yml as it did not pass its verify_file() method
Loading collection dominion_solutions.netbird from /home/ansible/.ansible/collections/ansible_collections/dominion_solutions/netbird
Using inventory plugin 'ansible_collections.dominion_solutions.netbird.plugins.inventory.netbird' to process inventory source '/home/ansible/ansible/inventory.netbird.yml'
toml declined parsing /home/ansible/ansible/inventory.netbird.yml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /home/ansible/ansible/inventory.netbird.yml with auto plugin: Unhandled exception when retrieving compose: unhashable type: 'AnsibleMapping'. unhashable type: 'AnsibleMapping'
  File "/usr/lib/python3/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/lib/python3/dist-packages/ansible/plugins/inventory/auto.py", line 59, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/home/ansible/.ansible/collections/ansible_collections/dominion_solutions/netbird/plugins/inventory/netbird.py", line 217, in parse
    self._options = self._read_config_data(path)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/ansible/plugins/inventory/__init__.py", line 240, in _read_config_data
    self.set_options(direct=config, var_options=self._vars)
  File "/usr/lib/python3/dist-packages/ansible/plugins/__init__.py", line 106, in set_options
    self._options = C.config.get_plugin_options(self.plugin_type, self._load_name, keys=task_keys, variables=var_options, direct=direct)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/ansible/config/manager.py", line 354, in get_plugin_options
    options[option] = self.get_config_value(option, plugin_type=plugin_type, plugin_name=name, keys=keys, variables=variables, direct=direct)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/ansible/config/manager.py", line 450, in get_config_value
    raise AnsibleError("Unhandled exception when retrieving %s:\n%s" % (config, to_native(e)), orig_exc=e)
[WARNING]:  * Failed to parse /home/ansible/ansible/inventory.netbird.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
  File "/usr/lib/python3/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/lib/python3/dist-packages/ansible/plugins/inventory/yaml.py", line 114, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]:  * Failed to parse /home/ansible/ansible/inventory.netbird.yml with ini plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file.
  File "/usr/lib/python3/dist-packages/ansible/inventory/manager.py", line 293, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/lib/python3/dist-packages/ansible/plugins/inventory/ini.py", line 138, in parse
    raise AnsibleParserError(e)
[WARNING]: Unable to parse /home/ansible/ansible/inventory.netbird.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped"
        ]
    }
}

I am using the hosted test version of netbird, if that makes a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant