Reputation: 53
Using the gcp_compute_instance command in ansible, how does one achieve the same as 'shut down' on the GCP console?
Upvotes: 1
Views: 726
Reputation: 53
Thanks @Zeitounator
status: TERMINATED does indeed work, but then one must be sure to set the deletion_protection parameter, else it complains, fatally.
- 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
Upvotes: 2
Reputation: 53
One could send a 'shutdown now' command after safely shutting down the database and other services that might not like a hard shut down:
- name: Send shutdown now command vi ssh
command: /usr/bin/ssh "{{ ansible_ssh_user }}"@"{{ host-ip-address }}" -C "sudo shutdown now"
delegate_to: localhost
Upvotes: 1