Search

Chapter 4. Integrating Event-Driven Ansible with the Red Hat Hybrid Cloud Console

download PDF

You can use Event-Driven Ansible to take advantage of Hybrid Cloud Console capabilities such as Red Hat Insights to continuously analyze your inventory for potential issues and recommendations. Event-Driven Ansible connects sources of events with corresponding actions through rules.

The integration with the Hybrid Cloud Console notifications service uses Event-Driven Ansible to trigger actions. Each account configures how and who can receive these events, with the ability to perform actions depending on the event type.

Contacting support

If you have any issues with the Hybrid Cloud Console integration with Event-Driven Ansible, contact Red Hat for support. You can open a Red Hat support case directly from the Hybrid Cloud Console by clicking Help (? icon) > Open a support case, or view more options from ? > Support options.

4.1. Configuring Event-Driven Ansible for integration with the Red Hat Hybrid Cloud Console

You can configure Event-Driven Ansible to receive event notifications from the Red Hat Hybrid Cloud Console or a third-party application.

Prerequisites

  • The ansible-rulebook CLI is installed. See Ansible rulebook installation for instructions.
  • You have Organization Administrator or Notifications administrator permissions for the Hybrid Cloud Console.

Procedure

  1. Connect your environment to the Red Hat Ansible Automation Hub:

    1. In the Hybrid Cloud Console, navigate to Ansible Automation Platform > Connect to Hub.
    2. Under Offline token, copy the string under The token will expire after 30 days of inactivity. Run the command below periodically to prevent your token from expiring.
    3. In a terminal window, paste the string that you copied in the previous step.
  2. Enter the following command to install the Red Hat Insights collection for Event-Driven Ansible:

    $ ansible-galaxy collection install redhat.insights_eda
  3. To install the Red Hat Insights requirements, enter the following command as the root user:

    # pip3 install -r ~/.ansible/collections/ansible_collections/redhat/insights_eda/requirements.txt
  4. Enter the following command and verify that redhat.insights_eda is included in the output:

    $ ansible-galaxy collection list

    Sample output for this command:

    # /home/username/.ansible/collections/ansible_collections
    Collection         Version
    ------------------ -------
    ansible.eda        1.3.8
    community.general  7.0.1
    redhat.insights_eda 1.0.0
  5. Use a text editor to create a YAML file that contains a simple Ansible rulebook that uses the Red Hat Insights collection. For example, create a file called simple-rulebook.yaml with the following content:

    ---
    - name: Listen for events from Red Hat Insights
      hosts: all
      sources:
        - redhat.insights_eda.insights:
      rules:
        - name: Handle Red Hat Insights payload
          condition: event.payload is defined
          action:
            debug:
              msg: "Received: {{ event.payload }}"

    This simple playbook uses the redhat.insights_eda.insights collection as the source. If an event with payload is defined, the contents of event.payload are displayed as output.

    The rulebook exposes an endpoint that is used to receive events and communicate with the Hybrid Cloud Console. See the Event-Driven Ansible for Red Hat Insights documentation in Ansible Automation Hub for more advanced examples for the Red Hat Insights Advisor, Compliance, and Vulnerability services.

  6. Create a YAML file that contains an associated playbook. For example, create a file called inventory.yaml that contains a simple inventory:

    all:
  7. Run the ansible-rulebook command to start your Event-Driven Ansible listener to listen for new events. In the following example, this command exposes your localhost on the default port 5000:

    $ ansible-rulebook --verbose --rulebook simple-rulebook.yml -i inventory.yml
  8. Run the curl command in a separate terminal window to verify that your Event-Driven Ansible listener is configured correctly, for example:

    $ curl -H 'Content-Type: application/json' -d "{\"payload\": \"Test incoming event\"}" localhost:5000/endpoint

    In this example, if the configuration is correct, a new message appears in the EDA listener window with the content of the event:

    Received: {'payload': 'Test incoming event'}
  9. In the Hybrid Cloud Console, navigate to Settings > Integrations.
  10. Select the Reporting & Automation tab.
  11. Click Add integration.
  12. Select Event-Driven Ansible as the integration type, and then click Next.
  13. In the Integration name field, enter a name for your integration (for example, My EDA Integration).
  14. Enter the URL that you configured in your Ansible rulebook into the Endpoint URL field. This is the endpoint that points to the Event-Driven Ansible listener.

    Note

    The Endpoint URL must include http:// or https://, for example https://<eda_hostname>:5000/endpoint.

    If necessary, ask the security administrator for your organization to configure access to the Red Hat Hybrid Cloud Console.

  15. Optional: Enter a Secret token if one is configured.

    Note

    A secret token is essential for protecting the data sent to the integration endpoint and should always be used when integrating the Hybrid Cloud Console with third-party applications.

  16. Click Next.
  17. Review the integration details, and then click Submit to enable the integration.

Your Event-Driven Ansible integration is now listed on the Integrations > Reporting & Automation page. Under Last connection attempt, the status is Ready to show the connection can accept notifications from the console.

Verification

Create a test notification to confirm you have correctly connected Event-Driven Ansible to the Hybrid Cloud Console:

  1. Next to your Event-Driven Ansible integration on the Integrations > Reporting & Automation page, click the options icon (⋮) and click Test.
  2. In the Integration Test screen, enter a message and click Send. If you leave the field empty, the Hybrid Cloud Console sends a default message.
  3. In the Event-Driven Ansible listener terminal, check for the message sent from the Hybrid Cloud Console.
  4. In the Hybrid Cloud Console, go to Notifications > Event Log and check that the Integration: Event-Driven Ansible event is listed with a green label.

Additional resources

  • For more information about setting up Notifications administrator permissions, see Configure User Access to manage notifications in Configuring notifications on the Red Hat Hybrid Cloud Console.
  • For more Event-Driven Ansible configuration information and examples of Red Hat Insights rulebooks, see the Documentation tab in the insights_eda collection available from the Ansible Automation Hub Collections page.

4.2. Creating the behavior group for the Event-Driven Ansible integration

A behavior group defines which notifications will be sent to external services such as Event-Driven Ansible when a specific event is received by the notifications service. You can link events from any Red Hat Hybrid Cloud Console service to your behavior group.

Prerequisites

Procedure

  1. In the Hybrid Cloud Console, navigate to Settings > Notifications.
  2. Under Notifications, select Configure Events.
  3. Select the application bundle tab you want to configure event notification behavior for: Red Hat Enterprise Linux, Console, or OpenShift.
  4. Click the Behavior Groups tab.
  5. Click Create new group to open the Create behavior group wizard.
  6. Type a name for the behavior group, and click Next.
  7. In the Actions and Recipients step, select Integration: Event-Driven Ansible from the Actions drop-down list.
  8. From the Recipient drop-down list, select the name of the integration you created (for example, My EDA Listener) and click Next.
  9. In the Associate event types step, select one or more events for which you want to send notifications (for example, Advisor: New recommendation), and click Next.
  10. Review your behavior group settings, and click Finish. The new behavior group appears on the Notifications page.

Verification

  1. Create an event that will trigger a Hybrid Cloud Console notification. See the Ansible Automation Hub page for an example.
  2. To test that the Hybrid Cloud Console integration was successful, in the Hybrid Cloud Console, go to Settings > Notifications > Event Log and check for an event that shows the label Integration: Event-Driven Ansible.

    img integ eda.event

    • If the label is green, the notification succeeded.
    • If the label is red, verify that the webhook has been properly created and exposed in Event-Driven Ansible, and that the correct webhook URL is configured in the Hybrid Cloud Console integration configuration.
Note

See Troubleshooting notification failures with the event log and integration settings in the notifications documentation for more details.

4.3. Additional resources

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.