Chapter 12. Integrate Ansible Automation Platform with governance


Integrate Red Hat Advanced Cluster Management for Kubernetes governance capabilities with Red Hat Ansible Automation Platform to enable automated remediation when policy violations occur.

Prerequisites

  • A supported version of Red Hat OpenShift Container Platform installed.
  • Install the latest supported version of Ansible Automation Platform. Red Hat Advanced Cluster Management supports Ansible Automation Platform version 3.7.3 and later.

Procedure

  1. Log in to the OpenShift Container Platform cluster console.
  2. Navigate to the Operator Lifecycle Manager and select the Ansible Automation Platform Resource Operator.
  3. In the Update Channel section, select stable-2.x-cluster-scoped.
  4. Select the All namespaces on the cluster (default) installation mode to complete installation.
  5. Optional: You can install the Ansible Automation Platform Resource Operator on a cluster other than the hub cluster. If you install the Ansible Automation Platform Resource Operator on the hub cluster, the operator version must match the Ansible Automation Platform Tower version.
  6. Ensure that the Ansible Automation Platform job template is idempotent when you run it. If you do not have Ansible Automation Platform Resource Operator, you can find it from the Red Hat OpenShift Software Catalog.

Configure a policy violation automation from the Red Hat Advanced Cluster Management console to begin automation tasks when a policy becomes non-compliant.

Required access: Cluster administrator

Prerequisites

  • Access to the Red Hat Advanced Cluster Management console.
  • An active Red Hat Ansible Automation Platform credential configured in Red Hat Advanced Cluster Management.

Procedure

  1. Log in to your Red Hat Advanced Cluster Management hub cluster.
  2. From the navigation menu, select Governance and click the Policies tab.
  3. Find the target policy in the table and click Configure in the Automation column.
  4. In the Ansible credential section, select your Ansible Automation Platform credential from the list.

    Note: This credential is copied to the same namespace as the policy. The generated AnsibleJob resource uses the Ansible Automation Platform credential to run the automation. Changes to the Ansible Automation Platform credential update automatically.

  5. Select an Ansible Automation Platform job template.
  6. In the Extra variables section, define parameter values in the extra_vars section of the PolicyAutomation resource.
  7. Select the automation frequency:

    • Run once mode
    • Run everyEvent mode
    • Disable automation
  8. Save your policy violation automation by selecting Submit. Clicking the View Job link from the Ansible job details side panel, naviagates to the job template on the Search page.
  9. Check to see that the automation is in the Automation column.

    Note: When you delete a policy that has an associated policy automation, the policy automation is automatically deleted as part of clean up.

Additional resources

Configure a policy violation automation from the command line interface by defining and applying a PolicyAutomation custom resource.

Prerequisites

  • Red Hat OpenShift Container Platform command line interface installed and authenticated to the hub cluster.
  • A target policy deployed on the hub cluster.

Procedure

  1. Log in to your hub cluster. Run the following command:

    oc login <hub_cluster_url>
  2. Find the name and namespace of the policy that you want to automate.
  3. Create a PolicyAutomation resource. Your YAML file might resemble the following example:

    apiVersion: policy.open-cluster-management.io/v1beta1
    kind: PolicyAutomation
    metadata:
      name: policyname-policy-automation
    spec:
      automationDef:
        extra_vars:
          your_var: your_value
        name: Policy Compliance Template
        secret: ansible-tower
        type: AnsibleJob
      mode: disabled
      policyRef: policyname
  4. Update the following fields within your resource definition:

    • spec.automationDef.name: Match your exact Red Hat Ansible Automation Platform job template name.
    • spec.automationDef.extra_vars: Add parameters passed directly to the automation template.
    • spec.mode: Set to once, everyEvent, or disabled.
    • spec.policyRef: Reference the exact target policy name.
  5. Create an Ansible Automation Platform credential secret containing the Ansible Tower token in the same namespace as the PolicyAutomation resource.
  6. Apply the configuration file the cluster. Run the following command:

    oc apply -f <filename>.yaml
  7. To configure an immediate run of the policy automation, add the following annotation to the PolicyAutomation resource:

    metadata:
      annotations:
        policy.open-cluster-management.io/rerun: "true"

12.3. Governance automation configuration

If there is a configured automation for a specific policy, you can select the automation to view more details. View the following descriptions of the schedule frequency options for your automation:

Manual run
Manually set this automation to run once. After the automation runs, it is set to disabled. Note: You can only select Manual run mode when the schedule frequency is disabled.
Run once mode
When a policy is violated, the automation runs one time. After the automation runs, it is set to disabled. After the automation is set to disabled, you must continue to run the automation manually. When you run once mode, the extra variable of target_clusters is automatically supplied with the list of clusters that violated the policy. The Ansible Automation Platform Job template must have PROMPT ON LAUNCH enabled for the EXTRA VARIABLES section (also known as extra_vars).
Run everyEvent mode
When a policy is violated, the automation runs every time for each unique policy violation per managed cluster. Use the DelayAfterRunSeconds parameter to set the minimum seconds before an automation can be restarted on the same cluster. If the policy is violated multiple times during the delay period and kept in the violated state, the automation runs one time after the delay period. The default is 0 seconds and is only applicable for the everyEvent mode. When you run everyEvent mode, the extra variable of target_clusters and Ansible Automation Platform Job template is the same as once mode.
Disable automation
When the scheduled automation is set to disabled, the automation does not run until the setting is updated.

The following variables are automatically provided in the extra_vars of the Ansible Automation Platform Job:

policy_name
The name of the noncompliant root policy that initiates the Ansible Automation Platform job on the hub cluster.
policy_namespace
The namespace of the root policy.
hub_cluster
The name of the hub cluster, which is determined by the value in the clusters DNS object.
policy_sets
This parameter contains all associated policy set names of the root policy. If the policy is not within a policy set, the policy_set parameter is empty.
policy_violations
This parameter contains a list of noncompliant cluster names, and the value is the policy status field for each noncompliant cluster.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

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.

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 Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top