Skip to content

redhat-cop/cloud.gcp_ops

Repository files navigation

cloud.gcp_ops roles/playbooks to demo Ansible on GCP

This repository hosts the cloud.gcp_ops Ansible Collection.

The collection includes a variety of Ansible roles and playbooks to help automate the management of resources on GCP.

Ansible version compatibility

This collection has been tested against following Ansible versions: >=2.14.0.

Python version compatibility

This collection requires Python 3.9 or greater.

Included content

Click on the name of a role to view that content's documentation:

Roles

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.

Playbooks

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.

Installation and Usage

Requirements

The google.cloud, community.libvirt and community.general collections MUST be installed in order for this collection to work.

Installation

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

Using this collection

Once installed, you can reference the cloud.gcp_ops collection content by its fully qualified collection name (FQCN), for example:

  - 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 }}"

See Also

Contributing to this collection

We welcome community contributions to this collection. If you find problems, please open an issue or create a PR against this collection repository.

Testing and Development

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

Integration tests require GCP credentials that must be provided to ansible-test. To authenticate using service account credentials:

  1. Create a service account key in the GCP console and save the json cred file.

  2. 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:

  1. Once you have installed gcloud and performed basic initialization (via gcloud init) run:

     gcloud auth application-default login
  2. 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.

License

GNU General Public License v3.0 or later

See LICENSE to see the full text.