My goal is to create a compute engine instance in Google cloud from which I can run ansible scripts to further create additional instances that will run containers via GKE.

I've figured out a number of things already:

  • How to create an instance where ansible and gce.py can run
  • How to give that instance sufficient rights to call apache-cloudlib
  • That ansible uses 'ansible_ssh_host' from inventory to make its connection

gce.py can either use the external IP address, or the internal IP address, depending on the value of the shell variable INVENTORY_IP_TYPE.

Neither of these are configured by the compute engine environment to use the SSH key generated by gcloud compute ssh-config, which looks like this:

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

*where is the public IP address

The end result is I can ssh to compute-instance.us-central1-a.project-name, but not to the public IP, or the private IP, without specifying the private key file ( google_compute_engine ), which is not an option in the gce.py script.

I can get the behavior I want by adding the internal IP as another entry for the Host:

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

.. however, there is a note in the config file that the file is automatically generated ( and not to do that thing ):

# 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.

Is there a known "right" way to get gce.py working from within google cloud, as it is, without hacking the ansible_ssh_host value the script generates?

  • 2
    You can hand-edit that section of your .ssh/config; it'll just get clobbered if you run gcloud compute config-ssh again. – Zachary Newman Jun 21 '16 at 15:05
  • Right. I was hoping for a solution that doesn't get clobbered if that command were executed again. – Cognitiaclaeves Jun 21 '16 at 20:53

Configuration specifications for Ansible's managed instances are defined in a playbook. Playbooks are YAML-formatted files containing collections of tasks that represent the desired state of the managed instance(s).

Ansible also requires an inventory listing of instances to manage. you will need to manage their inventory with a static file or a dynamic inventory plugin.

Creating Compute Engine resources, managing them, and destroying them can be performed using the Ansible command for applying playbooks:

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

More information about this matter can be found in this Help Center article.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.