2013-10-07 23:01:37 +02:00
|
|
|
# Copyright 2013 Google Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# The GCE inventory script has the following dependencies:
|
|
|
|
# 1. A valid Google Cloud Platform account with Google Compute Engine
|
|
|
|
# enabled. See https://cloud.google.com
|
|
|
|
# 2. An OAuth2 Service Account flow should be enabled. This will generate
|
|
|
|
# a private key file that the inventory script will use for API request
|
|
|
|
# authorization. See https://developers.google.com/accounts/docs/OAuth2
|
|
|
|
# 3. Convert the private key from PKCS12 to PEM format
|
|
|
|
# $ openssl pkcs12 -in pkey.pkcs12 -passin pass:notasecret \
|
|
|
|
# > -nodes -nocerts | openssl rsa -out pkey.pem
|
|
|
|
# 4. The libcloud (>=0.13.3) python libray. See http://libcloud.apache.org
|
|
|
|
#
|
|
|
|
# (See ansible/test/gce_tests.py comments for full install instructions)
|
|
|
|
#
|
|
|
|
# Author: Eric Johnson <erjohnso@google.com>
|
|
|
|
|
|
|
|
[gce]
|
|
|
|
# GCE Service Account configuration information can be stored in the
|
|
|
|
# libcloud 'secrets.py' file. Ideally, the 'secrets.py' file will already
|
|
|
|
# exist in your PYTHONPATH and be picked up automatically with an import
|
|
|
|
# statement in the inventory script. However, you can specify an absolute
|
|
|
|
# path to the secrets.py file with 'libcloud_secrets' parameter.
|
[GCE] Caching support for inventory script. (#18093)
* [GCE] Caching support for inventory script.
The GCE inventory script now supports reading from a cache rather than making the request each time. The format of the list and host output have not changed.
On script execution, the cache is checked to see if it older than 'cache_max_age', and if so, it is rebuilt (it can also be explicity rebuilt).
To support this functionality, the following have been added.
* Config file (gce.ini) changes: A new 'cache' section has been added to the config file, with 'cache_path' and 'cache_max_age' options to allow for configuration. There are intelligent defaults in place if that section and options are not found in the configuration file.
* Command line argument: A new --refresh-cache argument has been added to force the cache to be rebuild.
* A CloudInventoryCache class, contained in the same file has been added. As a seperate class, it allowed for testing (unit tests not included in this PR) and hopefully could be re-used in the future (it contains borrowed code from other inventory scripts)
* load_inventory_from_cache and do_api_calls_and_update_cache methods (, which were largely lifted from other inventory scripts, in a hope to promote consistency in the future) to determine if the cache is fresh and rebuild if necessary.
* A 'main' check, to support the script being imported and testable.
A new dictionary has been added to the list output, located at ['_meta']['stats'] that informs if the cache was used and how long it took to load the inventory (in 'cache_used' and 'inventory_load_time', respectively).
* fixed default value error; change cache time to 300
2016-10-24 22:32:50 +02:00
|
|
|
# This option will be deprecated in a future release.
|
2017-03-16 13:28:30 +01:00
|
|
|
libcloud_secrets =
|
2013-10-07 23:01:37 +02:00
|
|
|
|
|
|
|
# If you are not going to use a 'secrets.py' file, you can set the necessary
|
|
|
|
# authorization parameters here.
|
2017-03-16 13:28:30 +01:00
|
|
|
gce_service_account_email_address =
|
|
|
|
gce_service_account_pem_file_path =
|
|
|
|
gce_project_id =
|
|
|
|
gce_zone =
|
2013-10-07 23:01:37 +02:00
|
|
|
|
2016-06-14 23:13:21 +02:00
|
|
|
# Filter inventory based on on state. Leave undefined to return instances regardless of state.
|
|
|
|
# example: Uncomment to only return inventory in the running or provisioning state
|
|
|
|
#instance_states = RUNNING,PROVISIONING
|
|
|
|
|
|
|
|
|
2016-05-04 00:32:12 +02:00
|
|
|
[inventory]
|
|
|
|
# The 'inventory_ip_type' parameter specifies whether 'ansible_ssh_host' should
|
|
|
|
# contain the instance internal or external address. Values may be either
|
|
|
|
# 'internal' or 'external'. If 'external' is specified but no external instance
|
|
|
|
# address exists, the internal address will be used.
|
|
|
|
# The INVENTORY_IP_TYPE environment variable will override this value.
|
|
|
|
inventory_ip_type =
|
|
|
|
|
[GCE] Caching support for inventory script. (#18093)
* [GCE] Caching support for inventory script.
The GCE inventory script now supports reading from a cache rather than making the request each time. The format of the list and host output have not changed.
On script execution, the cache is checked to see if it older than 'cache_max_age', and if so, it is rebuilt (it can also be explicity rebuilt).
To support this functionality, the following have been added.
* Config file (gce.ini) changes: A new 'cache' section has been added to the config file, with 'cache_path' and 'cache_max_age' options to allow for configuration. There are intelligent defaults in place if that section and options are not found in the configuration file.
* Command line argument: A new --refresh-cache argument has been added to force the cache to be rebuild.
* A CloudInventoryCache class, contained in the same file has been added. As a seperate class, it allowed for testing (unit tests not included in this PR) and hopefully could be re-used in the future (it contains borrowed code from other inventory scripts)
* load_inventory_from_cache and do_api_calls_and_update_cache methods (, which were largely lifted from other inventory scripts, in a hope to promote consistency in the future) to determine if the cache is fresh and rebuild if necessary.
* A 'main' check, to support the script being imported and testable.
A new dictionary has been added to the list output, located at ['_meta']['stats'] that informs if the cache was used and how long it took to load the inventory (in 'cache_used' and 'inventory_load_time', respectively).
* fixed default value error; change cache time to 300
2016-10-24 22:32:50 +02:00
|
|
|
[cache]
|
|
|
|
# directory in which cache should be created
|
|
|
|
cache_path = ~/.ansible/tmp
|
|
|
|
|
|
|
|
# The number of seconds a cache file is considered valid. After this many
|
|
|
|
# seconds, a new API call will be made, and the cache file will be updated.
|
|
|
|
# To disable the cache, set this value to 0
|
|
|
|
cache_max_age = 300
|