ansible/ansible — pull request #8282 by kevinoid (2014-07-24 23:16:03+00:00)
Title: Improve GCE dynamic inventory configuration handling

Hey Ansible Developers,

Thanks for working on the GCE support, now that I've got it figured out it's really slick! I had a bit of difficulty figuring out the authentication initially, so I've written this pull request to address a couple of the issues that complicated it for me. I hope you find it useful:

The previous handling of configuration information for the GCE dynamic inventory plugin was sub-optimal in a couple ways:

- `gce.ini` was required even when `secrets.py` was on `PYTHONPATH`.
The error message would be `"ConfigParser.NoSectionError: No section: 'gce'"`.
- Several classes of errors would be silently ignored, resulting in
unrelated errors later in the script or empty values being used.
(e.g. syntax errors in `secrets.py`, incorrect `$GCE_INI_PATH`)
- If `gce.ini` and `secrets.py` were missing, the error message was
`"ConfigParser.NoSectionError: No section: 'gce'"`

This commit attempts to improve the error handling to address these
issues:

- `gce.ini` is no longer required if secrets.py can be imported
without it.
- An error is raised if `$GCE_INI_PATH` is non-empty and can not be read.
- If neither `gce.ini` nor `secrets.py` could be loaded, an error message
with a link to the documentation is printed.
- The logic for reading the preferences was moved into a new
`_get_gce_driver_args` method to avoid deep nesting by returning early.

Let me know if you think any of these changes are unwarranted or if you'd prefer a different implementation.

Thanks,
Kevin