Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Synchronize instance tags from Amazon EC2 and Microsoft Azure with Red Hat Insights

April 17, 2024
Jerome Marc
Related topics:
LinuxSecure Coding
Related products:
Red Hat Enterprise LinuxRed Hat Insights

Share:

    Tagging is a common feature offered today as part of system and platform management tools. Its goal is to provide a consistent way to organize, search and filter managed entities, thus improving reporting and overall operations management efficiency. A common challenge when dealing with different tools and platforms is the lack of tagging governance. Tags assignment and values can quickly run out of control unless best practices and rules are instored and honored in an organization. Often, organizations choose to define their taxonomy in a central configuration management database (CMDB) and use a discovery process to flag inconsistent tagging standards or associations in various platforms or management tools in use.

    In this article, we investigate how Red Hat Insights can synchronize its system tags with external sources. Red Hat Insights is a Software-as-a-Service offering that enables users to obtain actionable intelligence regarding their Red Hat Enterprise Linux environments, helping to identify and address operational and vulnerability risks before an issue results in downtime. 

    We provide examples for public cloud providers such as Amazon Elastic Compute Cloud (EC2) and Microsoft Azure. Both cloud providers offer system tagging or labeling to store metadata information. This is used to help categorize, search, and filter their inventory based on criteria relevant to the business (e.g., environment, team, cost center, workload, etc.) Our goal is to leverage existing tags set in these infrastructure providers to minimize friction to get going with our SaaS management offering. We automatically ingest tags from the cloud providers into Red Hat Insights and use them for managing and reporting in a consistent manner.

    What are System tags in Red Hat Insights?

    Red Hat Insights stores metadata tags as part of the System Inventory and offers them as a way to search and filter systems across applications. System tags consist of a key value pair storing information about the system and its context. They are set or imported from various sources. These include the Insights Client with a dedicated file for tags, Red Hat Satellite during its inventory synchronization, and the automated workload identification process performed by Insights to detect applications running on a system (e.g. SAP, Microsoft SQL, Red Hat Ansible Automation Platform). 

    Tags can be used in many different ways in Insights. You may, for example, want to get a list of findings from Advisor application affecting your production systems (assuming you have tagged your systems with their environment.) You may also want to use tags as part of Policies conditions, or get a list of all systems owned by one or more specific users. All these use cases (and more) can be fulfilled with system tags in Red Hat Insights.

    Setting system tags using Insights Client is achieved by editing the /etc/insights-client/tags.yaml file on the system itself. This file gets collected by Insights Client and its content processed every time the client runs (daily by default.) Values of the tags set in the file are used to replace existing values in Inventory. As such, system tags for a particular system get updated in Inventory at each insights client run.

    An example of the tags.yaml file is presented below.

    ---
    group: My Group
    Location: 
    - Geneva
    - Switzerland
    Application: RHEL Desktop
    Environment: Production
    Expiration Date: 
    Team: PMs
    Owner: Jerome Marc
    Slack: jmarc
    Contact: xxx

    The tags.yaml configuration file consists of a YAML file containing tag value pairs. Tags can get assigned multiple values (as described in the example file above for Location values). 

    Once processed, the file results in the assignment of multiple system tags. They are displayed in all applications with a system list by a tag icon next to the system name itself e.g., System Inventory, Advisor, Vulnerability, Compliance, and etc. Clicking on the tag icon opens up a window with all recorded tags for the system (Figure 1).

    Example of system tags assigned to rhel8desktop system.
    Figure 1: Example of system tags assigned to rhel8desktop system.
    Figure 1: Example of system tags assigned to rhel8desktop system.

    Values of system tags are used to filter the tables within Red Hat Insights. All possible tab names and values are presented when selecting a filter by tags (Figure 2). One or more tag value pairs can be selected in your filter. In the case of multiple selection, the OR operator is evaluated between tag value pairs.

    Example of all values presented for filter by tags.
    Figure 2: Example of all values presented for filter by tags.
    Figure 2: Example of all values presented for filter by tags.

    Tag value pairs can also be used as part of the Global Filtering capabilities to set which tags should be used for filtering consistently across all areas of Red Hat Insights. This global filter is available at the top of the page (Figure 3). Once set, all applications inherit the filters and only present the results according to the list of filtered systems.

    Example of all values presented for global filtering.
    Figure 3: Example of all values presented for global filtering.
    Figure 3: Example of all values presented for global filtering.

    Additional information on settings and using system tags in Red Hat Insights can be found in the product documentation.

    Amazon EC2 tags

    Tag metadata is a common tool to manage Amazon Web Services (AWS) resources. AWS Tags documentation describes how to create and manage them on the cloud platform. Additionally, AWS published a Best Practices for Tagging AWS Resources whitepaper providing guidance on tagging strategy, use cases, and best naming conventions to adopt.

    We are specifically interested in retrieving the tags from the instance running insights client. We plan to populate the tags.yaml file with AWS tags and get them uploaded via insights client.

    Note that the instance must be enabled to retrieve metadata. The procedure is documented in Allow access to tags in instance metadata and must be followed for the following to work.

    The get the instance tags for an instance documentation describes the commands to run to retrieve metadata tags from Linux instances. This can be achieved in two steps. First we grab the name of all tags set on the instance. Then we use the names to query for each individual value of the tag. It is important to note that AWS EC2 tags are limited to one single value, unlike insights-client tags.

    Retrieving Amazon EC2 tags from a script

    Our plan is to create a Shell script that runs on the instance to query for its metadata and retrieve all associated tags. The script populates the tags.yaml file with AWS tags. We plan to run the script every time prior to running insights client. 

    First we create a /usr/bin/get-aws-tags.sh shell script file with executable permissions.

    $ sudo touch /usr/bin/get-aws-tags.sh
    $ sudo chmod +x /usr/bin/get-aws-tags.sh
    $ ls -lal /usr/bin/get-aws-tags.sh
    -rwxr-xr-x. 1 root root 592 Mar 21 15:38 /usr/bin/get-aws-tags.sh

    The content of /usr/bin/get-aws-tags.sh should look like the following.

    #!/bin/sh
    TAG_FILE=/etc/insights-client/tags.yaml
    if [ ! -e $TAG FILE ]; then echo '---' > $TAG_FILE; fi
    TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && TAGS=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/tags/instance`
    sed -i '/^aws\/.*:/d' $TAG_FILE
    for TAG in $TAGS
    do
      VALUE=`curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/tags/instance/$TAG`
      echo aws/$TAG: $VALUE >> $TAG_FILE
    done

    The script queries for each AWS tag and gets its associated name. It then appends the tag to the end of the /etc/insights-client/tags.yaml file. Note that the AWS tags are cleaned up from the file initially to ensure invalid tags are removed and no duplicate is present.

    AWS tags get prefixed with aws/ to ensure they differ from regular insights-client tags. If no insights-client tag is present and/or if the /etc/insights-client/tags.yaml file does not exist, we create it and ensure it begins with --- (three dashes).

    You can confirm that the script works successfully by running it manually and validating that the AWS tags are appended at the end of the /etc/insights-client/tags.yaml file. The file should now contain a new line for each of the AWS tags associated with the instance. For example:

    $ cat /etc/insights-client/tags.yaml 
    ---
    aws/Name: ral-db02.hcc-lab.com
    aws/cost-center: xxxx
    aws/owner: jspinks
    aws/service-phase: prod
    aws/sleep_schedule: true

    Running our script prior to insights client

    When installed on Red Hat Enterprise Linux (RHEL) 7 and later, insights-client schedules a systemd timer /usr/lib/systemd/system/insights-client.timer that runs daily by default on the system.

    We can use an override.conf file for the systemd timer to add an ExecStartPre condition to the service. The condition runs our /usr/bin/get-aws-tags.sh script. We make sure that the timer doesn’t fail if something goes wrong with our script by prefixing our script path with a ‘-’ (dash) character. The following commands are used to create the file and display its content.

    $ sudo mkdir /etc/systemd/system/insights-client.service.d
    $ sudo touch /etc/systemd/system/insights-client.service.d/override.conf
    $ sudo cat /etc/systemd/system/insights-client.service.d/override.conf
    [Service]
    ExecStartPre=-/usr/bin/get-aws-tags.sh

    Now that the override.conf file is in place, we can reload the daemon and restart the timer with the following commands.

    $ sudo systemctl daemon-reload
    $ sudo systemctl restart insights-client.service

    We can also validate the status and outcome of the script by querying systemctl for insights-client.

    $ systemctl status insights-client
    ● insights-client.service - Insights Client
         Loaded: loaded (/usr/lib/systemd/system/insights-client.service; static)
        Drop-In: /etc/systemd/system/insights-client.service.d
                 └─override.conf
         Active: active (running) since Thu 2024-03-21 15:45:50 UTC; 6s ago
    TriggeredBy: ● insights-client.timer
           Docs: man:insights-client(8)
        Process: 17181 ExecStartPre=/usr/bin/get-aws-tags.sh (code=exited, status=0/SUCCESS)
       Main PID: 17182 (insights-client)
          Tasks: 2 (limit: 300)
         Memory: 43.5M (high: 1.0G max: 2.0G available: 980.4M)
            CPU: 2.018s
         CGroup: /system.slice/insights-client.service
                 ├─17182 /usr/libexec/platform-python /usr/bin/insights-client --retry 3
                 └─17194 /usr/libexec/platform-python /usr/lib/python3.9/site-packages/insights_client/run.py --retry 3

    You should see in the output a process executed as ExecStartPre with a 0/SUCCESS exit status.

    Validating the end-to-end process

    Our last validation consists of confirming AWS tags are present in our system inventory in Red Hat Insights. The list of tags contains all tags retrieved from different sources (e.g. insights-client or Satellite). We can use the filter with our aws/ prefix to get a list of all tags coming from AWS via insights-client (Figure 4). 

    Filtering AWS tags in Red Hat Insights.
    Figure 4: Filtering AWS tags in Red Hat Insights.
    Figure 4: Filtering AWS tags in Red Hat Insights.

    Now that our system tags are synchronized between AWS and Red Hat Insights, we can use the same tags in both platforms to filter our views and services, perform actions on specific systems and/or run automation according to system tags.

    In the remaining sections of this article, we provide the script required to perform the same operations with Microsoft Azure and retrieve system tags.

    Microsoft Azure tags

    Microsoft Azure encourages similar practices than AWS for managing and using system tags. They document conditions and limitations of using system tags in Use tags to organize your resources and management hierarchy. In particular, Azure offers a similar access to tag metadata from each instance. The procedure is documented in Azure Instance Metadata Service for virtual machines.

    Retrieving Microsoft Azure tags from a script

    We follow the exact same approach as AWS to populate our tags.yaml file with tags coming from Azure instances. The content of /usr/bin/get-azure-tags.sh script should look like the following.

    #!/bin/sh
    TAG_FILE=/etc/insights-client/tags.yaml
    if [ ! -e $TAG FILE ]; then echo '---' > $TAG_FILE; fi
    TAGS=`curl -s -H Metadata:true --noproxy "*" "http://169.254.169.254/metadata/instance/compute/tags?api-version=2021-02-01&format=text"`
    sed -i '/^azure\/.*:/d' $TAG_FILE
    IFS=';'
    for tag in $TAGS
    do
      echo "azure/$tag" | sed 's/:/: /' >> $TAG_FILE
    done

    The script queries for Azure tags at once and retrieve a semicolon separated string of name value pairs. It then parses the string and appends each tag to the end of the /etc/insights-client/tags.yaml file. Note that the Azure tags are cleaned up from the file initially to ensure invalid tags are removed and no duplicate is present.

    Similar to AWS, Azure tags get prefixed with azure/ to ensure they differ from regular insights-client tags. If no insights-client tag is present and/or if the /etc/insights-client/tags.yaml file does not exist, we create it and ensure it begins with --- (three dashes).

    You can confirm that the script works successfully by running it manually and validating that the Azure tags are appended at the end of the /etc/insights-client/tags.yaml file. The file should now contain a new line for each of the Azure tags associated with the instance. For example:

    $ cat /etc/insights-client/tags.yaml 
    ---
    azure/cost-center: xxxx
    azure/environment: production
    azure/owner: jmarc

    The same procedure as AWS can be followed to run the script prior to insights-client as part of its systemd timer. Once done, Azure tags will automatically be updated and synchronized with Red Hat Insights every time the client runs. We can use the same tags in both platforms to filter our views and services, perform actions on specific systems and/or run automation according to system tags.

    Conclusion 

    This article provides a way to synchronize system tags from instances running on Amazon EC2 or Microsoft Azure cloud services with Red Hat Insights. The shell scripts offered for each cloud provider are available on a GitHub repository for ease of use. With this mechanism in place, one can use the same taxonomy and naming convention used as part of their cloud management platforms within Red Hat Insights. Further, system tags are useful to obtain additional context and pass on further information to the platform. This can in turn be used for automation and/or driving operations processes.

    We welcome feedback to help improve and grow our product. Please share your experience with us by using the Feedback form located on the right side of the Hybrid Cloud Console.

    Last updated: March 20, 2025

    Related Posts

    • Convert CentOS Linux to RHEL using Red Hat Insights

    • Introduction to the Red Hat OpenShift deployment extension for Microsoft Azure DevOps

    • Deploy JBoss EAP on Microsoft Azure Red Hat OpenShift

    • It’s Time To Accelerate Your Application Development With Red Hat JBoss Middleware And Microsoft Azure

    • Detect network issues in Open vSwitch using Red Hat Insights

    Recent Posts

    • AI meets containers: My first step into Podman AI Lab

    • Live migrating VMs with OpenShift Virtualization

    • Storage considerations for OpenShift Virtualization

    • Upgrade from OpenShift Service Mesh 2.6 to 3.0 with Kiali

    • EE Builder with Ansible Automation Platform on OpenShift

    What’s up next?

    With Red Hat Insights, you can obtain actionable intelligence regarding your Red Hat Enterprise Linux environment to identify and address operational and vulnerability risks before an issue results in downtime. This cheat sheet covers the use of Red Hat Insights APIs. 

    Get the cheat sheet
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue