- ansible >= 2.9
- python >= 2.6
- requests >= 2.18.4
- google-auth >= 1.3.0
- gcp and service account
$ gcloud iam service-accounts keys create key-file [email protected]
- key-file: The name of the private key file.
- sa-name: The name of the service account to create a key for.
- project-id: Your Google Cloud project ID.
Value | GCP Command | Comments |
---|---|---|
machine types | $ gcloud compute machine-types list --filter="zone: your_zone" |
List all machine types available filtered by zone |
GCP Zone | $ gcloud compute regions list |
List all zones available |
Region | $ gcloud compute zones list |
List all regions available |
- Fill out all required variables in the role/build-instance/vars/mail.yml file.
- Run build playbook
$ ansible-playbook build-instance.yml
- Fill out all required variables in the role/destroy-instance/vars/mail.yml file.
- Run destroy playbook
$ ansible-playbook destroy-instance.yml
- Fill out all required variables in the role/create-disks/vars/mail.yml file.
- Run create-disk playbook
$ ansible-playbook create-disk.yml
- Fill out all required variables in the role/destroy-disks/vars/mail.yml file.
- Run destroy-disk playbook
$ ansible-playbook destroy-disk.yml
Using inventory.yml file as dynamic inventory you can list all GCP instances and create groups based on its tags.
-
Change both values into inventory.yml file: project_name and credentials_file
-
Run the command below lists to list all your inventory:
$ ansible-inventory -i inventory.yml --list
- You can view the populated inventory with:
$ ansible-inventory -i inventory.yml --graph
@all:
|--@Porto:
| |--34.0.0.1
| |--34.0.0.2
|--@Lisbon:
| |--35.0.0.1
|--@ungrouped:
|--@zone_us_central1_a:
| |--34.0.0.1
| |--34.0.0.2
| |--35.0.0.1