如何从运行在云中的实例中运行Ansible的gce.py脚本?

我的目标是在Google云中创build一个计算引擎实例,从中我可以运行可执行脚本来进一步创build将通过GKE运行容器的其他实例。

我已经想出了一些事情:

  • 如何创build一个ansible和gce.py可以运行的实例
  • 如何给这个实例足够的权限来调用apache-cloudlib
  • 这个ansible使用库存中的'ansible_ssh_host'来build立连接

gce.py可以使用外部IP地址或内部IP地址,具体取决于shellvariablesINVENTORY_IP_TYPE的值。

计算引擎环境都没有configuration这些configuration来使用由gcloud compute ssh-config生成的SSH密钥,如下所示:

Host compute-instance.us-central1-a.project-name Hostname 99.99.99.99 IdentityFile /home/user/.ssh/google_compute_engine 

*其中99.99.99.99是公共IP地址

最终的结果是,我可以ssh计算实例。中央1,a.project名称,但不公开的IP,99.99.99.99或私人IP,没有指定私钥文件(google_compute_engine),这是不gce.py脚本中的一个选项。

我可以通过添加内部IP作为Host的另一个条目来获得我想要的行为:

 Host compute-instance.us-central1-a.project-name 10.128.0.2 

..但是,在configuration文件中有一个注释,该文件是自动生成的(而不是做那件事):

 # The following has been auto-generated by "gcloud compute config-ssh" # to make accessing your Google Compute Engine virtual machines easier. # # To remove this blob, run: # # gcloud compute config-ssh --remove ... # You should not hand-edit this section, unless you are deleting it. # 

有没有一种已知的“正确”的方式来让gce.py在谷歌云中工作,而不会破坏脚本生成的ansible_ssh_host值?

Ansiblepipe理实例的configuration规范在一个剧本中定义。 手册是YAML格式的文件,其中包含代表受pipe实例所需状态的任务集合。

Ansible还需要清单列出要pipe理的实例。 您将需要使用静态文件或dynamic库存插件来pipe理他们的库存。

创build计算引擎资源,pipe理它们并销毁它们可以使用Ansible命令来执行应用程序:

ansible-playbook -i inventory.ini gce-playbook.yml

有关此问题的更多信息,请参阅此帮助中心文章 。