Unable to create instance on gcp using ansible

Viewed 40

Trying to create a gcp instance with ansible following the steps from this github link.

playbook:

---
 - hosts: localhost
   connection: local
   tasks:
       - name: creating instance
         gcp_compute_instance:
                 name: ansible instance
                 machine_type: e2-micro
                 disks:
                     - auto_delete: true
                       boot: true
                       initialize_params:
                           source_image: projects/debian-cloud/global/images/family/debian-11   
                 network_interfaces:
                     - access_configs:
                             - name: External NAT
                               type: ONE_TO_ONE_NAT
                 metadata:
                         startup-script: |
                                 #!/bin/bash
                                 sudo yum install httpd -y
                                 sudo echo "HELLO WORLD !!" > /var/www/html/index.html
                                 sudo systemctl restart httpd 
                 zone: us-central1-a
                 project: capstone-project-347806
                 auth_kind: serviceaccount
                 service_account_file: service.json
                 state: present

output:

PLAY [localhost] ****************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************** ok: [localhost]

TASK [creating instance] ******************************************************************************************************************************************************************** fatal: [localhost]: FAILED! => {"changed": false, "msg": "GCP returned error: {u'error': {u'message': u"Invalid value for field 'instance': 'ansible instance'. Must be a match of regex 'a-z?|[1-9][0-9]{0,19}'", u'code': 400, u'errors': [{u'reason': u'invalid', u'message': u"Invalid value for field 'instance': 'ansible instance'. Must be a match of regex 'a-z?|[1-9][0-9]{0,19}'", u'domain': u'global'}]}}"}

PLAY RECAP ********************************************************************************************************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

1 Answers

following the documentation for attribut name:

the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

so you cant have a space in the name, so the error says the same thing...

Related