Este conteúdo não está disponível no idioma selecionado.

Chapter 12. Ansible Automation Platform Resource Operator


12.1. Resource Operator overview

Resource Operator is a custom resource (CR) that you can deploy after you have created your platform gateway deployment.

With Resource Operator you can define resources such as projects, job templates, and inventories in YAML files.

automation controller then uses the YAML files to create these resources. You can create the YAML through the Form view that prompts you for keys and values for your YAML code. Alternatively, to work with YAML directly, you can select YAML view.

The Resource Operator provides the following CRs:

  • AnsibleJob
  • JobTemplate
  • Automation controller project
  • Automation controller schedule
  • Automation controller workflow
  • Automation controller workflow template:
  • Automation controller inventory
  • Automation controller credential

For more information on any of the above custom resources, see Using automation execution.

12.2. Using Resource Operator

The Resource Operator itself does not do anything until the user creates an object. As soon as the user creates an AutomationControllerProject or AnsibleJob resource, the Resource Operator starts processing that object.

Prerequisites

  • Install the Kubernetes-based cluster of your choice.
  • Deploy automation controller using the automation-controller-operator.

Next steps

After installing the automation-controller-resource-operator in your cluster, you must create a Kubernetes (k8s) secret with the connection information for your automation controller instance. Then you can use Resource Operator to create a k8s resource to manage your automation controller instance.

12.3. Connecting Resource Operator to platform gateway

To connect Resource Operator with platform gateway you must create a Kubernetes secret with the connection information for your automation controller instance.

Use the following procedure to create an OAuth2 token for your user in the platform gateway UI.

Note

You can only create OAuth 2 Tokens for your own user through the API or UI, which means you can only configure or view tokens from your own user profile.

Procedure

  1. Log in to Red Hat OpenShift Container Platform.
  2. In the navigation panel, select Access Management Users.
  3. Select the username you want to create a token for.
  4. Select Tokens Automation Execution
  5. Click Create Token.
  6. You can leave Applications empty. Add a description and select Read or Write for the Scope.

    Note

    Make sure you provide a valid user when creating tokens. Otherwise, you get an error message that you tried to issue the command without either specifying a user, or supplying a username that does not exist.

12.4. Creating a automation controller connection secret for Resource Operator

To make your connection information available to the Resource Operator, create a k8s secret with the token and host value.

Procedure

  1. The following is an example of the YAML for the connection secret. Save the following example to a file, for example, automation-controller-connection-secret.yml.

    apiVersion: v1
    kind: Secret
    metadata:
      name: controller-access
      type: Opaque
    stringData:
      token: <generated-token>
      host: https://my-controller-host.example.com/
    Copy to Clipboard Toggle word wrap
  2. Edit the file with your host and token value.
  3. Apply it to your cluster by running the kubectl create command:
kubectl create -f controller-connection-secret.yml
Copy to Clipboard Toggle word wrap

12.5. Creating custom resources for Resource Operator

Use the Resource Operator to manage automation controller resources directly from your Kubernetes cluster. This section provides the procedures for creating custom resources like AnsibleJob, JobTemplate, AnsibleProject, and more.

12.5.1. Creating an AnsibleJob custom resource

An AnsibleJob custom resource launches a job in the automation controller instance specified in the Kubernetes secret (automation controller host URL, token). You can launch an automation job on automation controller by creating an AnsibleJob resource.

Procedure

  1. Specify the connection secret and job template you want to launch.

    apiVersion: tower.ansible.com/v1alpha1
    kind: AnsibleJob
    metadata:
      generateName: demo-job-1 # generate a unique suffix per 'kubectl create'
    spec:
      connection_secret: controller-access
      job_template_name: Demo Job Template
    Copy to Clipboard Toggle word wrap
  2. Configure features such as, inventory, extra variables, and time to live for the job.

    spec:
      connection_secret: controller-access
      job_template_name: Demo Job Template
      inventory: Demo Inventory                    # Inventory prompt on launch needs to be enabled
      runner_image: quay.io/ansible/controller-resource-runner
      runner_version: latest
      job_ttl: 100
      extra_vars:                                  # Extra variables prompt on launch needs to be enabled
         test_var: test
      job_tags: "provision,install,configuration"  # Specify tags to run
      skip_tags: "configuration,restart"           # Skip tasks with a given tag
    Copy to Clipboard Toggle word wrap
    Note

    You must enable prompt on launch for inventories and extra variables if you are configuring those. To enable Prompt on launch, within the automation controller UI: From the Resources Templates page, select your template and select the Prompt on launch checkbox next to Inventory and Variables sections.

  3. Launch a workflow job template with an AnsibleJob object by specifying the workflow_template_name instead of job_template_name:

    apiVersion: tower.ansible.com/v1alpha1
    kind: AnsibleJob
    metadata:
      generateName: demo-job-1 # generate a unique suffix per 'kubectl create'
    spec:
      connection_secret: controller-access
      workflow_template_name: Demo Workflow Template
    Copy to Clipboard Toggle word wrap

12.5.2. Creating a JobTemplate custom resource

A job template is a definition and set of parameters for running an Ansible job. For more information see the Job Templates section of the Using automation execution guide.

Procedure

  • Create a job template on automation controller by creating a JobTemplate custom resource:

    apiVersion: tower.ansible.com/v1alpha1
    kind: JobTemplate
    metadata:
      name: jobtemplate-4
    spec:
      connection_secret: controller-access
      job_template_name: ExampleJobTemplate4
      job_template_project: Demo Project
      job_template_playbook: hello_world.yml
      job_template_inventory: Demo Inventory
    Copy to Clipboard Toggle word wrap

12.5.3. Creating an automation controller project custom resource

A Project is a logical collection of Ansible playbooks, represented in automation controller. For more information see the Projects section of the Using automation execution guide.

Procedure

  • Create a project on automation controller by creating an automation controller project custom resource:

    apiVersion: tower.ansible.com/v1alpha1
    kind: AnsibleProject
    metadata:
      name: git
    spec:
      repo: https://github.com/ansible/ansible-tower-samples
      branch: main
      name: ProjectDemo-git
      scm_type: git
      organization: Default
      description: demoProject
      connection_secret: controller-access
      runner_pull_policy: IfNotPresent
    Copy to Clipboard Toggle word wrap

12.5.4. Creating an automation controller schedule custom resource

Define an AnsibleSchedule custom resource to create a schedule on the automation controller, ensuring you specify the necessary apiVersion, kind, and a unique metadata.name.

Procedure

  • Create a schedule on automation controller by creating an automation controller schedule custom resource:

    apiVersion: tower.ansible.com/v1alpha1
    kind: AnsibleSchedule
    metadata:
      name: schedule
    spec:
      connection_secret: controller-access
      runner_pull_policy: IfNotPresent
      name: "Demo Schedule"
      rrule: "DTSTART:20210101T000000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=1"
      unified_job_template: "Demo Job Template"
    Copy to Clipboard Toggle word wrap

12.5.5. Creating an automation controller workflow custom resource

Workflows enable you to configure a sequence of disparate job templates (or workflow templates) that may or may not share inventory, playbooks, or permissions. For more information see the Workflows in automation controller section of the Using automation execution guide.

Procedure

  • Create a workflow on automation controller by creating a workflow custom resource:

    apiVersion: tower.ansible.com/v1alpha1
    kind: AnsibleWorkflow
    metadata:
      name: workflow
    spec:
      inventory: Demo Inventory
      workflow_template_name: Demo Job Template
      connection_secret: controller-access
      runner_pull_policy: IfNotPresent
    Copy to Clipboard Toggle word wrap

12.5.6. Creating an automation controller workflow template custom resource

A workflow job template links together a sequence of disparate resources to track the full set of jobs that were part of the release process as a single unit.

For more information see the Workflow job templates section of the Using automation execution guide.

Procedure

  • Create a workflow template on automation controller by creating a workflow template custom resource:

    apiVersion: tower.ansible.com/v1alpha1
    kind: WorkflowTemplate
    metadata:
      name: workflowtemplate-sample
    spec:
      connection_secret: controller-access
      name: ExampleTowerWorkflow
      description: Example Workflow Template
      organization: Default
      inventory: Demo Inventory
      workflow_nodes:
      - identifier: node101
        unified_job_template:
          name: Demo Job Template
          inventory:
            organization:
              name: Default
          type: job_template
      - identifier: node102
        unified_job_template:
          name: Demo Job Template
          inventory:
            organization:
              name: Default
          type: job_template
    Copy to Clipboard Toggle word wrap

12.5.7. Creating an automation controller inventory custom resource

By using an inventory file, Ansible Automation Platform can manage a large number of hosts with a single command.

Inventories also help you use Ansible Automation Platform more efficiently by reducing the number of command line options you have to specify. For more information see the Inventories section of the Using automation execution guide.

Procedure

  • Create an inventory on automation controller by creating an inventory custom resource:

    metadata:
      name: inventory-new
    spec:
      connection_secret: controller-access
      description: my new inventory
      name: newinventory
      organization: Default
      state: present
      instance_groups:
        - default
      variables:
        string: "string_value"
        bool: true
        number: 1
        list:
          - item1: true
          - item2: "1"
        object:
          string: "string_value"
          number: 2
    Copy to Clipboard Toggle word wrap

12.5.8. Creating an automation controller credential custom resource

Credentials authenticate the automation controller user when launching jobs against machines, synchronizing with inventory sources, and importing project content from a version control system.

SSH and AWS are the most commonly used credentials. For a full list of supported credentials see the Credential types section of the Using automation execution guide.

For help with defining values you can refer to the OpenAPI (Swagger) file for Red Hat Ansible Automation Platform API KCS article.

Tip

You can use https://<aap-instance>/api/controller/v2/credential_types/ to view the list of credential types on your instance. To get the full list use the following curl command:

export AAP_TOKEN="your-oauth2-token"
export AAP_URL="https://your-aap-controller.example.com"

curl -s -H "Authorization: Bearer $AAP_TOKEN" "$AAP_URL/api/controller/v2/credential_types/" | jq -r '.results[].name'
Copy to Clipboard Toggle word wrap

Procedure

  • Create an AWS or SSH credential on automation controller by creating a credential custom resource:

    • SSH credential:

      apiVersion: tower.ansible.com/v1alpha1
      kind: AnsibleCredential
      metadata:
        name: ssh-cred
      spec:
        name: ssh-cred
        organization: Default
        connection_secret: controller-access
        description: "SSH credential"
        type: "Machine"
        ssh_username: "cat"
        ssh_secret: my-ssh-secret
        runner_pull_policy: IfNotPresent
      Copy to Clipboard Toggle word wrap
    • AWS credential:

      apiVersion: tower.ansible.com/v1alpha1
      kind: AnsibleCredential
      metadata:
        name: aws-cred
      spec:
        name: aws-access
        organization: Default
        connection_secret: controller-access
        description: "This is a test credential"
        type: "Amazon Web Services"
        username_secret: aws-secret
        password_secret: aws-secret
        runner_pull_policy: IfNotPresent
      Copy to Clipboard Toggle word wrap
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat