This repository hosts the cloud.gcp_ops
Ansible Collection.
This collection is curated to provide users with a robust set of roles, playbooks, and rulebooks that simplify and streamline various GCP operations.
The google.cloud, community.libvirt and community.general collections MUST be installed in order for this collection to work.
This collection has been tested against following Ansible versions: >=2.15.0.
This collection requires Python 3.11 or greater.
Click on the name of a role to view that content's documentation:
Name | Description |
---|---|
cloud.gcp_ops.clone_on_prem_vm | A role to clone an existing on prem VM using the KVM hypervisor. |
cloud.gcp_ops.import_image_and_run_gcp_instance | A role that imports a local .raw image into an GCP custom image and run an GCP instance. |
cloud.gcp_ops.manage_machine_image | A role to create / delete a GCP custom machine image. |
Name | Description |
---|---|
cloud.gcp_ops.upload_file_to_cloud_storage | A playbook to upload a local file to GCP Cloud Storage. |
cloud.gcp_ops.move_vm_from_on_prem_to_gcp | A playbook to migrate an existing on prem VM running on KVM hypervisor to GCP. |
To consume this Validated Content from Automation Hub, please ensure that you add the following lines to your ansible.cfg file.
[galaxy]
server_list = automation_hub
[galaxy_server.automation_hub]
url=https://cloud.redhat.com/api/automation-hub/
auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token
token=<SuperSecretToken>
The token can be obtained from the Automation Hub Web UI.
Once the above steps are done, you can run the following command to install the collection.
ansible-galaxy collection install cloud.gcp_ops
Once installed, you can reference the cloud.gcp_ops collection content by its fully qualified collection name (FQCN), for example:
# Create GCP custom machine image.
- hosts: all
vars:
project: "{{ gcp_project }}"
auth_kind: "{{ gcp_cred_kind }}"
service_account_file: "{{ gcp_cred_file }}"
tasks:
- name: Create a new custom machine image
ansible.builtin.include_role:
name: cloud.gcp_ops.manage_machine_image
vars:
manage_machine_image_operation: create
manage_machine_image_source_disk_name: "{{ disk_name }}"
manage_machine_image_image_name: "{{ image_name }}"
manage_machine_image_image_description: "{{ description }}"
# clone an existing on prem VM using the KVM hypervisor.
- hosts: kvm
tasks:
- name: Import 'cloud.gcp_ops.clone_on_prem_vm' role
ansible.builtin.include_role:
name: cloud.gcp_ops.clone_on_prem_vm
vars:
clone_on_prem_vm_source_vm_name: "{{ clone_on_prem_vm_source_vm_name }}"
clone_on_prem_vm_image_name: "{{ clone_on_prem_vm_image_name }}"
clone_on_prem_vm_local_image_path: "{{ clone_on_prem_vm_local_image_path }}"
clone_on_prem_vm_uri: "{{ clone_on_prem_vm_uri }}"
We welcome community contributions to this collection. If you find problems, please open an issue or create a PR against this collection repository. See CONTRIBUTING.md for more details.
The project uses ansible-lint
and black
.
Assuming this repository is checked out in the proper structure,
e.g. collections_root/ansible_collections/cloud/gcp_ops/
, run:
tox -e linters
Sanity and unit tests are run as normal:
ansible-test sanity
Integration tests require GCP credentials that must be provided to ansible-test. To authenticate using service account credentials:
-
Create a service account key in the GCP console and save the json cred file.
-
Create the file
tests/integration/cloud-config-gcp.ini
containing the following:[default] gcp_project: <project ID> gcp_cred_file: </path/to/cred/file.json> gcp_cred_kind: serviceaccount
To authenticate with application default credentials via the GCloud CLI:
-
Once you have installed
gcloud
and performed basic initialization (viagcloud init
) run:gcloud auth application-default login
-
Create the file
tests/integration/cloud-config-gcp.ini
containing the following:[default] gcp_project: <project ID> gcp_cred_kind: application
Once credentials are set up, run all integration tests with ansible-test integration
or run a subset of integration tests with ansible-test integration <target>
This collection is tested using GitHub Actions. To know more about CI, refer to CI.md.
For the latest supported versions, refer to the release notes below.
If you encounter issues or have questions, you can submit a support request through the following channels:
- GitHub Issues: Report bugs, request features, or ask questions by opening an issue in the GitHub repository.
- Ansible Community: Engage with the Ansible community on the Ansible Project Mailing List or Ansible Forum.
See the raw generated changelog.
GNU General Public License v3.0 or later
See LICENSE to see the full text.