在 GCP 中部署 windows 实例时添加启动脚本
To add a startup script when deploying a windows instance in GCP
我正在使用 gcp_compute_instance 模块中的元数据选项在 GCP 中部署一个 Windows 实例和几个启动脚本,因为实例正在按预期创建,但启动脚本没有开始执行,请参考以下任务并建议我需要做哪些更改来执行启动脚本(首先创建一个带密码的本地管理员用户,然后将 winrm 基本身份验证设置为 true)
- name: create a instance
gcp_compute_instance:
state: present
name: "{{ vm_name }}"
machine_type: "{{ machine_type }}"
metadata:
startup-script: |
New-LocalUser -AccountNeverExpires:$true -Password ( ConvertTo-SecureString -AsPlainText -Force 'Password123!') -Name 'adminuser1' |Add-LocalGroupMember -Group administrators
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
disks:
- auto_delete: true
boot: true
source: "{{ disk }}"
- auto_delete: true
boot: false
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
- auto_delete: true
boot: false
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
network_interfaces:
- network: "{{ network }}"
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: instance
The fine manual 说在您的情况下,密钥应该是 windows-startup-script-ps1:
因为该脚本是 powershell
我正在使用 gcp_compute_instance 模块中的元数据选项在 GCP 中部署一个 Windows 实例和几个启动脚本,因为实例正在按预期创建,但启动脚本没有开始执行,请参考以下任务并建议我需要做哪些更改来执行启动脚本(首先创建一个带密码的本地管理员用户,然后将 winrm 基本身份验证设置为 true)
- name: create a instance
gcp_compute_instance:
state: present
name: "{{ vm_name }}"
machine_type: "{{ machine_type }}"
metadata:
startup-script: |
New-LocalUser -AccountNeverExpires:$true -Password ( ConvertTo-SecureString -AsPlainText -Force 'Password123!') -Name 'adminuser1' |Add-LocalGroupMember -Group administrators
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
disks:
- auto_delete: true
boot: true
source: "{{ disk }}"
- auto_delete: true
boot: false
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
- auto_delete: true
boot: false
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
network_interfaces:
- network: "{{ network }}"
zone: "{{ zone }}"
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
scopes:
- https://www.googleapis.com/auth/compute
register: instance
The fine manual 说在您的情况下,密钥应该是 windows-startup-script-ps1:
因为该脚本是 powershell