# Bug in gcp\_compute\_instance? Deleting vm labels where turning or and off

**URL:** <https://forum.ansible.com/t/bug-in-gcp-compute-instance-deleting-vm-labels-where-turning-or-and-off/3873>\
**Category:** Get Help\
**Tags:** gcp, rhel, playbook, awx, collections\
**Created:** [February 14, 2024, 3:52pm UTC](https://forum.ansible.com/t/bug-in-gcp-compute-instance-deleting-vm-labels-where-turning-or-and-off/3873 "2024-02-14T15:52:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![valkiriaaquatica](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/valkiriaaquatica/32/1308_2.png) [@valkiriaaquatica](https://forum.ansible.com/u/valkiriaaquatica)\
**Post date:** [February 14, 2024, 3:52pm UTC](https://forum.ansible.com/t/bug-in-gcp-compute-instance-deleting-vm-labels-where-turning-or-and-off/3873/1 "2024-02-14T15:52:58Z")

</div>

## Hi, During a test i noticed that if I power on or power off a machine using the module above, the labels of the machine are removed (No other script or interaction is being used, just this task).

Playbook example straightforward:

```auto
name: PowerON VM
hosts: all
gather_facts: false
vars:
   ansible_python_interpreter: /usr/bin/python3
tasks:
        - name: Power ON nstance-1
          gcp_compute_instance:
            status: RUNNING 
            project: project1
            zone: europe-southwest1-a
            name: instance-1
          delegate_to: localhost
          tags:
            - encender_individual

```

```auto
--- Ansible version -- 
bash-4.4# ansible --version
ansible [core 2.15.6]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.18 (main, Sep 22 2023, 17:58:34) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3.9)
jinja version = 3.1.2
libyaml = True

```

— This collection versions:

```auto
community.google 1.0.0
google.cloud 1.3.

```

— Runnig enviroment:  
`Is an execution enviroement in AAP in a container of image RHEL 8.9 running on the base OS RHEL 8.8`

Any hint? What is happening? I have tried to add the deletion\_protection:true but still doesent work

— For someone who wants to reproduce it —

##### STEPS TO REPRODUCE

1 Create an instance in GCP  
2 Create a static/dynamic/smart inventory with the data of the machine and prepare the credentials to authorize  
3Add a label with a key and value to the machine you created  
4 Create the following playbook (handle authorization as you need)

```auto
name: PowerON VM
hosts: all
gather_facts: false
vars:
   ansible_python_interpreter: /usr/bin/python3
tasks:
    name: Power ON nstance-1
      gcp_compute_instance:
        status: RUNNING
        project: your_project
        zone: your_zone
        name: name_of_your_instance
      delegate_to: localhost
      tags:
        - poweron

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![atul\_mohan](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@atul\_mohan](https://forum.ansible.com/u/atul_mohan)\
**Post date:** [February 3, 2025, 5:58am UTC](https://forum.ansible.com/t/bug-in-gcp-compute-instance-deleting-vm-labels-where-turning-or-and-off/3873/3 "2025-02-03T05:58:31Z")

</div>

```auto
name: PowerON VM
hosts: all
gather_facts: false
vars:
   ansible_python_interpreter: /usr/bin/python3
tasks:
  - name: Power ON instance-1 with labels preserved
    gcp_compute_instance:
      status: RUNNING
      project: your_project
      zone: your_zone
      name: name_of_your_instance
      labels: "{{ lookup('google.cloud.gcp_compute_instance', name='name_of_your_instance', zone='your_zone', project='your_project').labels }}"
    delegate_to: localhost
    tags:
      - poweron

```
