Reputation: 53
I have a GCP Compute Engine VM instance that is in a stopped state. How can I start it up, specifically using Ansible?
Please note that this must be in its own Ansible playbook, as opposed to the playbook that created the VM.
Upvotes: 0
Views: 1909
Reputation: 53
Thanks @abdennour-toumi.
Correct, status: RUNNING works well.
Be sure to set the deletion_protection parameter, else the playbook fails.
---
- name: Start a GCP instance which is currently stopped
hosts: to_start_up
gather_facts: false
tasks:
- name: Start a GCP VM instance which is currently stopped
gcp_compute_instance:
name: "{{ inventory_hostname_short }}"
deletion_protection: no
machine_type: "{{ gcp_ce_machine_type }}"
zone: "{{ gcp_ce_zone }}"
project: "{{ gcp_ce_project_name }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_ce_service_account_keyfile }}"
status: RUNNING
delegate_to: localhost
Upvotes: 1
Reputation: 93163
Ansible cannot connect to your device (or machine) if your SSHD process is off.
so How can Ansible connect to your device (or machine) if not only SSHD process is off, but also the whole machine is off ?
Ansible connects on yourbehalf to your machine and makes sure that your desired state meets the actual state.
However, you have solution as your are dealing with IaaS.
In this case, you need to target your localhost and call the module gcp_compute_instance
with status: RUNNING
- name: create a instance
gcp_compute_instance:
name: test_object
machine_type: n1-standard-1
#. ...
status: RUNNING # <-- this is what u need
Please make sure you have ansible 2.8 or above otherwise there is no param called status in the previous versions.
Upvotes: 3