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
- Log in to the OpenShift Container Platform cluster console.
- Navigate to the Operator Lifecycle Manager and select the Ansible Automation Platform Resource Operator.
- In the Update Channel section, select stable-2.x-cluster-scoped.
- Select the All namespaces on the cluster (default) installation mode to complete installation.
- 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.
- 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.
Additional resources
12.1. Create a policy violation automation from the console Copy linkLink copied to clipboard!
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
- Log in to your Red Hat Advanced Cluster Management hub cluster.
- From the navigation menu, select Governance and click the Policies tab.
- Find the target policy in the table and click Configure in the Automation column.
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
AnsibleJobresource uses the Ansible Automation Platform credential to run the automation. Changes to the Ansible Automation Platform credential update automatically.- Select an Ansible Automation Platform job template.
-
In the Extra variables section, define parameter values in the
extra_varssection of thePolicyAutomationresource. Select the automation frequency:
- Run once mode
- Run everyEvent mode
- Disable automation
- 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.
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
12.2. Create a policy violation automation from the command line interface Copy linkLink copied to clipboard!
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
Log in to your hub cluster. Run the following command:
oc login <hub_cluster_url>- Find the name and namespace of the policy that you want to automate.
Create a
PolicyAutomationresource. 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: policynameUpdate 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 toonce,everyEvent, ordisabled. -
spec.policyRef: Reference the exact target policy name.
-
-
Create an Ansible Automation Platform credential secret containing the Ansible Tower token in the same namespace as the
PolicyAutomationresource. Apply the configuration file the cluster. Run the following command:
oc apply -f <filename>.yamlTo configure an immediate run of the policy automation, add the following annotation to the
PolicyAutomationresource:metadata: annotations: policy.open-cluster-management.io/rerun: "true"
12.3. Governance automation configuration Copy linkLink copied to clipboard!
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 todisabled, you must continue to run the automation manually. When you run once mode, the extra variable oftarget_clustersis automatically supplied with the list of clusters that violated the policy. The Ansible Automation Platform Job template must havePROMPT ON LAUNCHenabled for theEXTRA VARIABLESsection (also known asextra_vars). - Run everyEvent mode
-
When a policy is violated, the automation runs every time for each unique policy violation per managed cluster. Use the
DelayAfterRunSecondsparameter 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 theeveryEventmode. When you runeveryEventmode, the extra variable oftarget_clustersand 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
clustersDNSobject. 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_setparameter is empty. policy_violations-
This parameter contains a list of noncompliant cluster names, and the value is the policy
statusfield for each noncompliant cluster.