Share Feedback to help us keep improving.
Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 13. Ansible Automation Platform Resource Operator
13.1. Resource Operator overview Link kopierenLink in die Zwischenablage kopiert!
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.
13.2. Using Resource Operator Link kopierenLink in die Zwischenablage kopiert!
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.
Procedure
-
After installing the
automation-controller-resource-operatorin 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.
13.3. Connecting Resource Operator to platform gateway Link kopierenLink in die Zwischenablage kopiert!
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.
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
- Log in to Red Hat OpenShift Container Platform.
-
In the navigation panel, select
. - Select the username you want to create a token for.
-
Select
- Click .
You can leave Applications empty. Add a description and select Read or Write for the Scope.
NoteMake 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.
13.4. Creating a automation controller connection secret for Resource Operator Link kopierenLink in die Zwischenablage kopiert!
To make your connection information available to the Resource Operator, create a k8s secret with the token and host value.
Procedure
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/- Edit the file with your host and token value.
-
Apply it to your cluster by running the
kubectl createcommand:
kubectl create -f controller-connection-secret.yml
13.5. Create custom resources for Resource Operator Link kopierenLink in die Zwischenablage kopiert!
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.
13.5.1. Creating an AnsibleJob custom resource Link kopierenLink in die Zwischenablage kopiert!
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
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 TemplateConfigure 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 tagNoteYou 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
page, select your template and select the Prompt on launch checkbox next to Inventory and Variables sections. Launch a workflow job template with an AnsibleJob object by specifying the
workflow_template_nameinstead ofjob_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
13.5.2. Creating a JobTemplate custom resource Link kopierenLink in die Zwischenablage kopiert!
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
13.5.3. Creating an automation controller project custom resource Link kopierenLink in die Zwischenablage kopiert!
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
13.5.4. Creating an automation controller schedule custom resource Link kopierenLink in die Zwischenablage kopiert!
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"
13.5.5. Creating an automation controller workflow custom resource Link kopierenLink in die Zwischenablage kopiert!
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
13.5.6. Creating an automation controller workflow template custom resource Link kopierenLink in die Zwischenablage kopiert!
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
13.5.7. Creating an automation controller inventory custom resource Link kopierenLink in die Zwischenablage kopiert!
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
13.5.8. Creating an automation controller credential custom resource Link kopierenLink in die Zwischenablage kopiert!
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.
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'
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: IfNotPresentAWS 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