Google cloud platform 使用Ansible,如何临时关闭GCP VM实例,而不是删除它?

Google cloud platform 使用Ansible,如何临时关闭GCP VM实例,而不是删除它?,google-cloud-platform,ansible,Google Cloud Platform,Ansible,在ansible中使用gcp_compute_instance命令,如何实现与gcp控制台上的“关机”相同的效果?在安全关闭数据库和其他可能不喜欢硬关机的服务后,可以发送“立即关机”命令: - name: Send shutdown now command vi ssh command: /usr/bin/ssh "{{ ansible_ssh_user }}"@"{{ host-ip-address }}" -C "sudo shutdow

在ansible中使用gcp_compute_instance命令,如何实现与gcp控制台上的“关机”相同的效果?

在安全关闭数据库和其他可能不喜欢硬关机的服务后,可以发送“立即关机”命令:

- name: Send shutdown now command vi ssh
  command: /usr/bin/ssh "{{ ansible_ssh_user }}"@"{{ host-ip-address }}" -C "sudo shutdown now"
  delegate_to: localhost
谢谢@Zeitounator

状态:终止确实有效,但必须确保设置删除保护参数,否则它会发出致命的抱怨

   - name: Shut down a GCP instance temporarily
      gcp_compute_instance:
        name: "{{ inventory_hostname_short }}"
        deletion_protection: no
        machine_type: "{{ gcp_ce_machine_type }}"
        disks:
          - auto_delete: 'false'
            boot: 'true'
            source: "{{ disk }}"
        network_interfaces:
        - network:
          access_configs:
          - name: External NAT
            nat_ip:
            type: ONE_TO_ONE_NAT
        zone: "{{ gcp_ce_zone }}"
        project: "{{ gcp_ce_project_name }}"
        auth_kind: serviceaccount
        service_account_file: "{{ gcp_ce_service_account_keyfile }}"
        status: TERMINATED
      delegate_to: localhost

一个选项是发送“立即关机”命令,然后安全地关闭服务:不执行任务?我似乎找不到使用状态的工作示例如果我想当然地认为文档是准确的,您应该只需将
状态:已终止
添加到创建实例的实际任务中,和
status:RUNNING
当您想再次启动它时。不幸的是,我没有GCP帐户可供测试。