不使用libcloud,而使用GoogleComputeEngine的DynamicInventoryScript进行尝试

环境

    • OSX 10.10.2 (Yosemite)

 

    Python 2.7.9 (OSXにデフォルトインストールされてるPython)

安装所需的库文件。

※ 在我的环境中,如果不安装这个,就无法运行。

$ brew install gmp
$ sudo pip install pycrypto

获取库存脚本和ini文件

$ wget https://github.com/ansible/ansible/blob/devel/plugins/inventory/gce.ini -P ~/.ansible
$ wget https://raw.githubusercontent.com/ansible/ansible/devel/plugins/inventory/gce.py -P ~/.ansible
$ chmod 755 ~/.ansible/gce.py

以原生方式在中国把以下句子改写成中文,只需提供一个选项:无需使用libcloud,将设置记录在gce.ini文件中。

#!/usr/bin/python
# Copyright 2013 Google Inc.
#
# This file is part of Ansible
#

...

[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.
libcloud_secrets = 

# If you are not going to use a 'secrets.py' file, you can set the necessary
# authorization parameters here.
gce_service_account_email_address = example@developer.gserviceaccount.com
gce_service_account_pem_file_path = ~/.ansible/example.pem
gce_project_id = example-test-12345

确认动作

$ ~/.ansible/gce.py | jq .

{
  "tag_http-server": [
    "example"
  ],
  "asia-east1-a": [
    "example"
  ],
  "f1-micro": [
    "example"
  ],
  "status_running": [
    "example"
  ],
  "persistent_disk": [
    "example"
  ],
  "network_default": [
    "example"
  ],
  "_meta": {
    "hostvars": {
      "example": {
        "gce_uuid": "aaaaaaaaaaaaaaaaaaaaaaaaaaa",
        "gce_public_ip": "000.000.000.000",
        "ansible_ssh_host": "000.000.000.000",
        "gce_private_ip": "00.000.00.0",
        "gce_id": "aaaaaaaaaaaaaaaaaaaa",
        "gce_image": null,
        "gce_description": null,
        "gce_machine_type": "f1-micro",
        "gce_tags": [
          "http-server"
        ],
        "gce_name": "example",
        "gce_zone": "asia-east1-a",
        "gce_status": "RUNNING",
        "gce_network": "default",
        "gce_metadata": {
          "os": "example"
        }
      }
    }
  }
}
广告
将在 10 秒后关闭
bannerAds