Using the Google Compute Engine module to create Ubuntu instances doesn't work as expected

Hello,

Let me start out with the playbook I’m using (any authentication info you see below has been modified from the original so no worries about privacy concerns):

---
- name: Create instance(s)
  hosts: localhost
  connection: local
  gather_facts: no

  vars:
    service_account_email: 457671988709-m1346pm0lmrfb733qqjnmife8na6h2wj@developer.gserviceaccount.com
    pem_file: ./roles/google/files/pkey.pem
    project_id: rosy-stronghold-765
    machine_type: n1-standard-1
    image: ubuntu
    zone: us-central1-a

  tasks:

   - name: Launch instances
     gce:
         instance_names: dev
         machine_type: "{{ machine_type }}"
         image: "{{ image }}"
         service_account_email: "{{ service_account_email }}"
         pem_file: "{{ pem_file }}"
         project_id: "{{ project_id }}"
         zone: "{{ zone }}"

I’ve been trying to use ansible to create a Ubuntu based instance, but no avail. Originally, I was getting this error from Ansible:

PLAY [all] ********************************************************************

PLAY [Create instance(s)] *****************************************************

TASK: [Launch instances] ******************************************************
failed: [localhost] => {“changed”: false, “failed”: true}
msg: Missing required create instance variable

FATAL: all hosts have already failed – aborting

After doing a fair amount of research, I found out that the stable 0.16.0 version of apache-libcloud did not seem to support Ubuntu, at least based on the source code in the gce.py driver. Because of this, I installed the development version of the library which actually does have support for Ubuntu, at least from what I can see in the source:

if (partial_name.startswith(‘debian’) or
partial_name.startswith(‘backports’) or
partial_name.startswith(‘nvme-backports’)):
image = self._match_images(‘debian-cloud’, partial_name)
elif partial_name.startswith(‘centos’):
image = self._match_images(‘centos-cloud’, partial_name)
elif partial_name.startswith(‘sles’):
image = self._match_images(‘suse-cloud’, partial_name)
elif partial_name.startswith(‘rhel’):
image = self._match_images(‘rhel-cloud’, partial_name)
elif partial_name.startswith(‘windows’):
image = self._match_images(‘windows-cloud’, partial_name)
elif partial_name.startswith(‘container-vm’):
image = self._match_images(‘google-containers’, partial_name)
elif partial_name.startswith(‘coreos’):
image = self._match_images(‘coreos-cloud’, partial_name)
elif partial_name.startswith(‘opensuse’):
image = self._match_images(‘opensuse-cloud’, partial_name)
elif partial_name.startswith(‘ubuntu’):
image = self._match_images(‘ubuntu-os-cloud’, partial_name)

With this new library, Ansible no longer threw the error above and it now went ahead with the play. However, I noticed that no matter what combination of the string “ubuntu” I use for the “image” parameter, Ansible will always default to creating a CentOS image (I’m guessing that’s a default somewhere) and so, I’m kind of stuck now as to what could be going wrong.

Has anyone experienced similar issues when creating Ubuntu issue? Any assistance with this would be greatly appreciated.

Luis

It was reported on stacktrace as well:

http://stackoverflow.com/questions/27605262/other-images-in-ansible-and-gce

not sure you saw that

Peter