diff --git a/lib/ansible/modules/cloud/google/gce_instance_template.py b/lib/ansible/modules/cloud/google/gce_instance_template.py index 4962a3320c..e8b7a44314 100644 --- a/lib/ansible/modules/cloud/google/gce_instance_template.py +++ b/lib/ansible/modules/cloud/google/gce_instance_template.py @@ -290,6 +290,7 @@ def create_instance_template(module, gce): external_ip = module.params.get('external_ip') service_account_permissions = module.params.get( 'service_account_permissions') + service_account_email = module.params.get('service_account_email') on_host_maintenance = module.params.get('on_host_maintenance') automatic_restart = module.params.get('automatic_restart') preemptible = module.params.get('preemptible') @@ -369,7 +370,10 @@ def create_instance_template(module, gce): bad_perms.append(perm) if len(bad_perms) > 0: module.fail_json(msg='bad permissions: %s' % str(bad_perms)) - ex_sa_perms.append({'email': "default"}) + if service_account_email is not None: + ex_sa_perms.append({'email': str(service_account_email)}) + else: + ex_sa_perms.append({'email': "default"}) ex_sa_perms[0]['scopes'] = service_account_permissions gce_args['service_accounts'] = ex_sa_perms