Search

Chapter 5. Using the Command Generator

download PDF

The Command Generator is used to generate commands for launching operational playbooks provided by the Ansible-on-clouds operational playbook collection.

The process involves five steps:

  1. Pull the ansible-on-clouds-ops container image.
  2. List the available playbooks.
  3. Use a command generator to generate a data file and the next command to run. command_generator_vars and the command_generator are implemented using a docker container and are run using the docker command line interface.
  4. Populate the data file and run the previous generated command. This generates the final command with all parameters.

    Note

    When this step is complete, you can save the generated command and run the playbook when it is required.

  5. Run the final command.

Prerequisites

  • Docker
  • A GCP credentials file
  • An internet connection to Google Cloud

5.1. Pulling the ansible-on-clouds-ops container image

Pull the Docker image for the Ansible on Clouds operational container with the same tag version as your deployment.

Note

Before Pulling the docker image, make sure you are logged in to registry.redhat.com using docker. Use the following command to login to registry.redhat.com.

$ docker login registry.redhat.io

For more information about registry login, see Registry Authentication

For example, if your foundation deployment version is 2.3.20230221-00, you must pull the operational image with tag 2.3.20230221.

Use the following commands:

$ export IMAGE=registry.redhat.io/ansible-on-clouds/ansible-on-clouds-ops-rhel8:2.3.20230221
$ docker pull $IMAGE --platform=linux/amd64

For EMEA regions (Europe, Middle East, Africa) run the following command instead:

$ export IMAGE=registry.redhat.io/ansible-on-clouds/ansible-on-clouds-ops-emea-rhel8:2.3.20230221
$ docker pull $IMAGE --platform=linux/amd64

5.2. Listing the available playbooks

Procedure

  1. For the list of available playbooks without details, use the following command.

    $ docker run --rm $IMAGE command_generator_vars | grep Playbook
    
    The current version of the operational playbooks collection contains the following playbooks:
    
    Playbook: aws_add_extension_nodes
    Playbook: aws_backup_stack
    Playbook: aws_deployment_inventory
    Playbook: aws_remove_extension_nodes
    Playbook: aws_restore_stack
    Playbook: aws_upgrade
    Playbook: gcp_aap_health_check
    Playbook: gcp_backup_deployment
    Playbook: gcp_create_external_load_balancer
    Playbook: gcp_delete_external_load_balancer
    Playbook: gcp_deployment_inventory
    Playbook: gcp_health_check
    Playbook: gcp_list_deployments
    Playbook: gcp_nodes_health_check
    Playbook: gcp_restore_deployment
    Playbook: gcp_setup_logging_monitoring
    Playbook: gcp_upgrade
  2. To provide a list of all available playbooks, and to use the command generator, use the following command.

    $ docker run --rm $IMAGE command_generator_vars

    This provides a list of playbooks and a command similar to the following:

    ===============================================
    Playbook: gcp_upgrade
    Description: Performs the upgrade of the Ansible Automation Platform from GCP Marketplace components to the latest version.
    -----------------------------------------------
    Performs the upgrade of the Ansible Automation Platform from GCP Marketplace components to the latest version.
    
    -----------------------------------------------
    Command generator template:
    
    docker run --rm $IMAGE command_generator gcp_upgrade [--ansible-config ansible_config_path>] \
    -d <deployment_name> -c <cloud_credentials_path> --extra-vars 'gcp_compute_region=<gcp_compute_region> gcp_compute_zone=<gcp_compute_zone> gcp_backup_taken=<true|false>'
    ===============================================

5.3. Generating the data file

Procedure

  1. Run the command generator.

    $ docker run --rm -v <local_directory_data_file>:/data $IMAGE command_generator_vars <playbook_name> --output-data-file /data/<data-file>.yml

    The outputs of this command are the command to run and the data file template. The data file is also saved in your <local_data_file_directory>. This is the template which you populate with your data.

    The following example uses the gcp_backup_deployment playbook.

    $ docker run --rm -v <local_data_file_directory>:/data $IMAGE command_generator_vars gcp_backup_deployment \
    --output-data-file /data/backup.yml
  2. Producing the following output.

    ===============================================
    Playbook: gcp_backup_deployment
    Description: This playbook is used to backup the AoC Self-managed GCP environment.
    -----------------------------------------------
    This playbook is used to backup the AoC Self-managed GCP environment.
    For more information regarding backup and restore, visit our official documentation -
    
    -----------------------------------------------
    Command generator template:
    
    docker run --rm -v /tmp:/data $IMAGE command_generator gcp_backup_deployment --data-file /data/backup.yml
    
    Data template:
    
    gcp_backup_deployment:
      cloud_credentials_path:
      deployment_name:
      extra_vars:
        gcp_bucket_backup_name:
        gcp_compute_region:
        gcp_compute_zone:
    
    ===============================================

5.4. Populating the data file

Procedure

  • Edit the data-file generated in Generating the data file.

    Any attribute that represents a path must be an absolute path. The command_generator automatically mounts a volume for it in the final command.

    For example, in the case of the gcp_backup_deployment playbook, the file becomes:

    gcp_backup_deployment
      cloud_credentials_path: /path/to/credentials
      deployment_name: my-deployment
      extra_vars:
        cp_bucket_backup_name: my-bucket
        gcp_compute_region: us-east1
        gcp_compute_zone: us-east1-b

5.5. Running the generated command

Procedure

  1. Ensure that the mounted volume points to the directory where the data file is.

    For the gcp_backup_deployment playbook example, this is:

    $ docker run --rm -v /tmp:/data $IMAGE command_generator gcp_backup_deployment --data-file /data/backup.yml

    Which generates the following output:

    Command to run playbook:
    
    $ docker run --rm --env PLATFORM=GCP -v /path/to/credentials:/home/runner/.gcp/credentials:ro \
    --env ANSIBLE_CONFIG=../gcp-ansible.cfg  $IMAGE\ redhat.ansible_on_clouds.gcp_backup_deployment \
    -e 'gcp_service_account_credentials_json_path=/home/runner/.gcp/credentials  \
    gcp_deployment_name=my-deployment gcp_compute_region=us-east1 gcp_compute_zone=us-east1-b'

    This new command has the required parameters, environment variables and mounted volumes to run the playbook.

  2. Run the generated command. You can save this command to rerun it later if required.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.