尝试用ansible创建一个gcp实例,遵循这个github链接中的步骤。
剧本:
---
- 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产出:
播放本地主机****************************************************************************************************************************************************************************
任务收集事实********************************************************************************************************************************************************************** ok:本地主机
任务创建实例********************************************************************************************************************************************************************致命:本地主机:失败!=> {“已更改”:false,"msg":"GCP返回错误:{u'error':{u‘’message‘:U“”字段’实例的无效值“:'ansible instance‘。必须匹配regex‘a?\\1-9{0,19}’“,u‘’code‘:400,u’错误‘:[{u’理由‘:U’无效‘,u’‘message’:U”字段‘实例’的无效值“:'ansible instance‘。必须匹配regex‘a-z?x 1-9{0,19}’“,u‘’domain‘:U’‘global’}”}“}
播放重述********************************************************************************************************************************************************************************** localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
发布于 2022-04-21 13:25:16
遵循attribut name的文档
名称必须为1-63个字符,并与正则表达式
[a-z]([-a-z0-9]*[a-z0-9])?相匹配,这意味着第一个字符必须是小写字母,以下所有字符必须是破折号、小写字母或数字,但最后一个字符除外,后者不能是破折号。
所以你不能有一个space的名字,所以错误说同样的事情.
https://stackoverflow.com/questions/71954665
复制相似问题