nbering / terraform-inventory

An Ansible dynamic inventory script to pair with nbering/terraform-provider-ansible.
MIT License
176 stars 52 forks source link

Failed to parse with script plugin error post macOS upgrade (Terraform remote state?) #25

Closed balaji-dutt closed 2 years ago

balaji-dutt commented 2 years ago

Hi,

I'm aware that there is an open issue (#21) but given it's a couple of years old I'm not sure the workarounds mentioned in there are still correct. In addition, I've started seeing this error quite recently after upgrading to macOS Monterey so I'm not sure if it's some type of broken dependency.

I'm seeing the following error when I try to run any ansible command with the Inventory script:

❯ ansible -i /Users/balaji/Applications/terraform.py online -m ping
/usr/local/Cellar/ansible@5.7.1/5.7.1/libexec/lib/python3.10/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
  "class": algorithms.Blowfish,
[WARNING]:  * Failed to parse /Users/balaji/Applications/terraform.py with script plugin: Inventory script
(/Users/balaji/Applications/terraform.py) had an execution error: env: python: No such file or directory
[WARNING]:  * Failed to parse /Users/balaji/Applications/terraform.py with ini plugin: /Users/balaji/Applications/terraform.py:3: Error
parsing host definition ''''': No closing quotation
[WARNING]: Unable to parse /Users/balaji/Applications/terraform.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: online

Terraform state is stored remotely, but I'm able to retrieve Terraform state in the same directory without any error:

❯ terraform state list
data.aws_ssm_parameter.proxmox_api_address
data.aws_ssm_parameter.proxmox_login
data.aws_ssm_parameter.proxmox_login_secret
ansible_host.airconnect
ansible_host.devdesktop
... [output snipped]

Is there some way to debug this issue further? I've tried adding the ANSIBLE_TF_DIR variable when running ansible commands but that doesn't seem to change anything.

cooperaj commented 2 years ago

Python has apparently been removed in the latest macOS version. env: python: No such file or directory is literally saying that python can't be found.

Would recommend installing python via homebrew and ensuring it's linked on your path as versionless (i.e. python not python@3.9).

You'll still hit issues with the script being incompatible with python 3.9 but that can be fixed by amending line 390 to remove the encoding specification.

balaji-dutt commented 2 years ago

Python has apparently been removed in the latest macOS version. env: python: No such file or directory is literally saying that python can't be found.

D-oh! That'll teach me to not read error messages properly. python3 is available on $PATH as a versionless executable so I just modified Line 1 to reference python3

You'll still hit issues with the script being incompatible with python 3.9 but that can be fixed by amending line 390 to remove the encoding specification.

Thanks for pointing out that gotcha as well @cooperaj. Once I made the change to the env line and the edit on Line 390, things started working again.