When I run the following command in the directory ansible/contrib/inventory
ansible -i ec2.py all -m ping
and I got the following error:
[WARNING]: * Failed to parse /Users/hehe/Projects/python/ansible/contrib/inventory/ec2.py with
ini plugin: /Users/hehe/Projects/python/ansible/contrib/inventory/ec2.py:3: Error parsing host
definition ''''': No closing quotation
[WARNING]: Unable to parse /Users/hehe/Projects/python/ansible/contrib/inventory/ec2.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'
My OS is MacOS and ansible version is 2.6.1. Did something or configurations be lost?
Ansible is trying to read the content instead of executing the script because of missing execution bit.
So you need to set the execution bit on ec2.py to make it work.
HI Dick, thanks for your feedback. I know this docs and the command, but this command can not work. I want to know the error reason and how I should do?
Error origin:The file you have downloaded is not marked as executable, so when you pass as inventory file, Ansible tries to read (not to execute it).
Ansible tries to read as “ini” file (you have the first warning) but, of course, this is not an ini file so it raises the warning.
Solution:
As Dick suggest, you need to mark as executable the script (chmod +x ec2.py) and launch again the ansible command (ansible -i ec2.py all -m ping).
Have you posted all the warnings provided? If so, it looks like you’ve disabled the script plugin, which is necessary to parse the contrib scripts. Check your ansible.cfg [inventory] enable_plugins section and the ANSIBLE_INVENTORY_ENABLED environment var.
If you just left out some of the warnings, examine the one that starts with [WARNING]: * Failed to parse /path/to/ec2.py with script plugin: to see what’s wrong. You can debug with ansible-inventory -i ec2.py --graph and by running the script alone python ec2.py.