mlimaloureiro / ansible-maas-dynamic-inventory

Dynamic inventory for MAAS
14 stars 7 forks source link

line 32 def __init__(self, maas_api_url: str, maas_api_key: str) #13

Open seanwhe opened 4 years ago

seanwhe commented 4 years ago

when run using: python3 maas.py --list The script returns correct dynamic inventory JSON from MAAS.

When run using: ansible all -i maas.py -m ping The script returns:

ansible all -i maas.py -m ping [WARNING]: * Failed to parse /home/netadmin/ansible-tst/maas.py with script plugin: Inventory script (/home/netadmin/ansible-tst/maas.py) had an execution error: File "/home/netadmin/ansible-tst/maas.py", line 32 def init(self, maas_api_url: str, maas_api_key: str): ^ SyntaxError: invalid syntax

[WARNING]: Unable to parse /home/netadmin/ansible-tst/maas.py as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

When run using: ansible apache-1 -i maas.py -m ping [WARNING]: * Failed to parse /home/netadmin/ansible-tst/maas.py with script plugin: Inventory script (/home/netadmin/ansible-tst/maas.py) had an execution error: File "/home/netadmin/ansible-tst/maas.py", line 32 def init(self, maas_api_url: str, maas_api_key: str): ^ SyntaxError: invalid syntax

[WARNING]: Unable to parse /home/netadmin/ansible-tst/maas.py as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

[WARNING]: Could not match supplied host pattern, ignoring: apache-1

seanwhe commented 4 years ago

Appended to this. The script returns the same results when passed to ansible-playbook

seanwhe commented 4 years ago

I eventually got this running.

Had to install the requirements.txt using pip3 install -r requirements.txt

Then change the shebang to #!/usr/bin/env python3

mikimtm commented 4 years ago

I have similar issue but not same.

python3 maas.py --list Traceback (most recent call last): File "maas.py", line 313, in <module> Main() File "maas.py", line 204, in __init__ print(self._list()) File "maas.py", line 299, in _list self.inventory = self._group_machines_by_tag() File "maas.py", line 281, in _group_machines_by_tag machines = self.fetcher.fetch_machines_grouped_by_tags() File "maas.py", line 77, in fetch_machines_grouped_by_tags tags_summary = self._fetch_tags_summary() File "maas.py", line 121, in _fetch_tags_summary return self._api_call(url) File "maas.py", line 136, in _api_call response = json.loads(request.text) File "/usr/lib64/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib64/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib64/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

mikimtm commented 4 years ago

I can't get inventory to list at all

mikimtm commented 4 years ago

I got it running as well. Seems I had to list it by tags. It only list machines that has tags. Any tags.