Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add, update, delete or purge machine labels #622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valkiriaaquatica
Copy link

SUMMARY

add, delete, update and purge all labels in compute instances in GCP. The idea is base on the modules that are unmaintained
and not part of the google cloud collection ,but adding the new used functions of google cloud, don't need to install "google-api-python-client" and a purge options to delete all tags.

  • The "similar" modules that exist are: google.cloud.gcp_compute_instance but is focus on creating the machine and
    how is shown in this issue: gcp_compute_instance module doesn't update instance tags #307 it applies no changes.
  • The other similar is this community.google.gce_labels module but it it unmaintained and is not part of google.cloud collection... but is the one that appears if you searching in google by: add label to compute machine in gcp ansible_
ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

gcp_compute_instance_labels

ADDITIONAL INFORMATION 2 --> EXAMPLES

Before to add a tag using an unmaintained community.google.gce_labels:

    - name: Add labels on an existing instance 
      community.google.gce_labels:
        credentials_file: "route_to_your_json"
        project_id: "123456789"
        labels:
          enviroment: dev
        resource_name: "machine_name"
        resource_location: "europe-southwest1-a" 
        resource_type: "instances"
        state: present

Now (not big difference, just using new funciont in the back)

    - name: Add new labels while maintaing the existi labels of the machine. 
      google.gcp.gcp_compute_instance_labels:
        name: "machine_name"
        zone: "europe-southwest1-a"
        project: "123456789"
        auth_kind: "serviceaccount"
        service_account_file: "route_to_your_json"
        labels: 
          enviroment: dev
          office: colorado
          

Before
To delete all labels you had to get all labels with gcp_compute_instance_info module and then iterate with community.google.gce_labels to delete all the labels in a compute machine

Now

    - name: Remove all labels of a machine
      google.gcp.gcp_compute_instance_labels:
        name: "instance_name"
        zone: "europe-southwest1-a"
        project: "1233456789"
        auth_kind: "serviceaccount"
        service_account_file: "path_to_json"
        purge_labels: True
        state: "absent"

Also added a functionailty to let the user decide to remove previous labels of the machine before adding the new label wit the "mode" functionality.

    - name: Add new label and delete old labels
      google.gcp.gcp_compute_instance_labels:
        name: "machine_name"
        zone: "europe-southwest1-a"
        project: "123456789"
        auth_kind: "serviceaccount"
        service_account_file: "path_to_json"
        mode: "replace"
        labels: 
          enviroment: "dev"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant