Red Hat Training

A Red Hat training course is available for Red Hat Satellite

Chapter 3. Managing Content Life Cycle

This section shows how to use hammer to create Content Views and to promote them through life cycle environments.

3.1. Creating a Life Cycle Environment

Life cycle environments represent stages of the content life cycle. This section shows how to view and create life cycle environments with hammer. By default, the Library environment is present for each organization. Use the following syntax to create a new life cycle environment:

$ hammer lifecycle-environment create \
--name <env_name> \
--description "<env_description>" \
--organization-label <org_label> \
--prior <prior_env_name>

Example 3.1. Creating a Life Cycle Environment

This example shows how to create a new environment based on Library for the ACME organization (assuming the organization name is stored in a shell variable):

$ hammer lifecycle-environment create \
--name Development \
--description "Initial testing" \
--organization $ORG \
--prior Library

You can create another life cycle environment based on Development using the --prior option.

To view existing life cycle environments, issue the following command:

$ hammer lifecycle-environment list --organization-label <org_label>

The output of the above command can look as follows:

---|-------------|------------
ID | NAME        | PRIOR
---|-------------|------------
2  | Library     |
5  | Development | Library
6  | Testing     | Development
---|-------------|------------

For more information on commands related to life cycle environments, see the output of hammer lifecycle-environment --help.

3.2. Creating a Content View

Content Views are subsets of content from the Library created by intelligent filtering. You can publish and promote Content Views into life cycle environments that make content available for different uses (typically Dev, QA, and Production). To create a Content View, issue the following command:

$ hammer content-view create \
--name <cv_name> \
--repository-ids <repo_ID1>,<repo_ID2>,<repo_ID3> \
--description "<cv_description>" \
--organization-label <org_label>

The --repository-ids option adds the selected repositories to the Content View, use the hammer repository list command to find the IDs. It is also possible to omit this option to create an empty Content View that you can modify later using the update or add-repository subcommands.

Example 3.2. Creating a Content View

The following example creates a Content View under the ACME organization and assigns it three repositories:

$ hammer content-view create \
--name cv-rhel7-server \
--repository-ids 1,2,3 \
--description "Initial CV for RHEL 7" \
--organization $ORG

Example 3.3. Creating a Composite Content View

A Composite Content View is comprised of one or more Content Views. This example shows how to create a Composite Content View from two existing Content Views:

$ hammer content-view create \
--name ccv-rhel7-server-scl \
--description "CCV for RHEL7 and Software Collections" \
--organization $ORG \
--composite --component-ids 2,6

Find the IDs for the --component-ids option by executing hammer content-view list.

There are three content types you can add to the Content View: RPM packages, Puppet modules, and Docker images.

3.2.1. Adding Repositories to a Content View

Use the following command to add repositories to an existing Content View:

$ hammer content-view update \
--repository-ids <repo_ID1>,<repo_ID2>... \
--name <cv_name> \
--organization-label <org_label>

The above command is useful for populating an empty Content View with repositories. Note that it will overwrite any existing repositories, therefore to increase the number of repositories in a Content View, use:

$ hammer content-view add-repository \
--organization-label <org_label> \
--name <cv_name> \
--repository-id <repo_ID>

Similarly, you can use the remove-repository subcommand to remove a repository from the Content View. Use hammer content-view info to inspect repositories in a Content View.

Example 3.4. Filtering Packages for a Content View – Excluding a Package

Filters allow you to select a subset of packages from a repository (either by including or excluding) to create customized Content Views. This example shows how to create a filter to exclude the emacs package from the cv-rhel7-server Content View.

First create a filter for the Content View in the organization:

$ hammer content-view filter create \
--type rpm \
--name exclude-emacs \
--description "Excluding emacs package" \
--inclusion false \
--organization $ORG \
--repository-ids 1,2,3 \
--content-view cv-rhel7-server

Find the repository IDs by executing hammer repository list. Create a rule to exclude packages with name starting with "emacs" and add it to the filter as follows:

$ hammer content-view filter rule create \
--name "emacs*" \
--organization $ORG \
--content-view cv-rhel7-server \
--content-view-filter exclude-emacs

As a result, hosts using the cv-rhel7-server Content View will not have access to the emacs package. You can add multiple rules to a filter, see the output hammer content-view rule create --help for the full list of filtering parameters. To inspect rules present in a filter, issue the following command:

$ hammer content-view filter rule list \
--content-view cv-rhel7-server \
--content-view-filter exclude-emacs \
--organization $ORG

Example 3.5. Filtering Packages for a Content View – Limiting Errata by Date

This example shows how to create a filter to exclude errata released before a specific date from the cv-rhel7-server Content View. For more information on errata management see Chapter 8, Managing Errata. Create a filter for the Content View as follows:

$ hammer content-view filter create \
--type erratum \
--name limit-errata-by-date \
--description "Excluding errata by date" \
--inclusion false \
--organization $ORG \
--repository-ids 1,2,3 \
--content-view cv-rhel7-server

Create a rule to exclude errata with a name starting with "emacs" and add it to the filter as follows:

$ hammer content-view filter rule create \
--end-date <YYYY-MM-DD> \
--organization $ORG \
--content-view cv-rhel7-server \
--content-view-filter limit-errata-by-date \
--types enhancement,bugfix,security

3.2.2. Adding Puppet Modules to a Content View

To add a Puppet module to a Content View, first upload this module to a Puppet repository within a custom product. Use the commands from Section 2.3.4, “Creating a Custom Repository” to create a product with a repository, and to upload a Puppet module to the repository.

To add a Puppet module to a Content View, issue the following command:

$ hammer content-view puppet-module add \
--content-view <cv_name> \
--name <module_name>

Example 3.6. Adding a Puppet Module to a Content View

This example shows how to add a Puppet module from an external source to the cv-rhel7-server Content View.

  1. Download the concat module (that constructs files from multiple text fragments) from Puppet Forge:

    $ wget -O /tmp/puppetlabs-concat-1.2.5.tar.gz https://forgeapi.puppetlabs.com
    /v3/files/puppetlabs-concat-1.2.3.tar.gz
  2. Create a Puppet repository under the ACME-puppet product and upload the module to this repository (the example assumes repository ID is 6):

    $ hammer product create \
    --name "ACME-puppet" \
    --organization $ORG
    $ hammer repository create \
    --organization $ORG \
    --product ACME-puppet \
    --name "ACME Puppet Repository" \
    --content-type puppet \
    --url "https://forge.puppetlabs.com/"
    $ hammer repository upload-content \
    --organization $ORG \
    --product ACME-puppet \
    --id 6 \
    --path /tmp/puppetlabs-concat-1.2.5.tar.gz
  3. Add the module to the Content View using the id, name, or author parameters. To find the exact values, enter:

    $ hammer puppet-module list --organization $ORG
    ---|--------|------------|--------
    ID | NAME   | AUTHOR     | VERSION
    ---|--------|------------|--------
    1  | concat | puppetlabs | 1.2.3
    ---|--------|------------|--------

    To add the module to the Content View, issue:

    $ hammer content-view puppet-module add \
    --name concat \
    --content-view cv-rhel7-server \
    --organization $ORG

    To verify if the module has been added successfully, issue the following command:

    $ hammer content-view puppet-module list \
    --content-view cv-rhel7-server \
    --organization $ORG

3.2.3. Adding Docker Images to a Content View

You can upload Docker images directly to the dedicated repository as follows:

$ hammer repository upload-content --path <image_archive> --id <repo_id>

Replace <image_archive> with a path to the archive containing the Docker image. Use <repo_id> to identify the repository of docker content type. Then you can add this repository to the Content View.

3.3. Publishing a Content View

By publishing a Content View you make it visible and usable by hosts. Use the following command to publish a selected Content View:

$ hammer content-view publish \
--id <cv_ID> \
--organization-label <org_label> \
--async

Find the <cv_ID> of the Content View to be published in the output of the hammer content-view list command. Published Content Views become available in the Library environment. To verify the Content View status, issue the following command:

$ hammer content-view info --id <cv_ID>

3.4. Promoting a Content View

Promoting is the act of moving a Content View from one life cycle environment to another. To do so, issue the following command.

$ hammer content-view version promote \
--content-view <cv_name> \
--organization-label <org_label> \
--to-lifecycle-environment <env_name>

Here, <env_name> stands for the name of target life cycle environment.

Example 3.7. Promoting a Content View Through the Life Cycle Environment Path

The following Bash script promotes the selected Content View from Library through all life cycle environments in the ACME organization:

ORG="ACME"
CV_ID=1

for i in $(hammer --csv lifecycle-environment list --organization $ORG | grep -vi '^ID' | awk -F, {'print $1'} | sort -n)
do
   hammer content-view version promote --organization $ORG --to-lifecycle-environment-id $i --id $CV_ID
done

To verify if the Content View has been promoted correctly, issue the following command:

$ hammer content-view version info --id 1

3.5. Performing an Incremental Update of a Content View

Incremental updates enable modifying a published Content View without the need to promote a new Content View version through the life cycle environment. As a result of the incremental update, a new minor Content View version is created. Incremental updates are useful for fast emergency updates, you can use them to add errata, packages, or Puppet modules.

To create an incremental update adding new packages to a Content View, issue:

$ hammer content-view version incremental-update \
--content-view-version-id <cv_ID> \
--packages <pkg_name1>,<pkg_name2> \
--lifecycle-environment-ids <env_ID1>, <env_ID2>,...

Find the Content View version ID in the output of hammer Content View version list. Instead of supplying packages with the --packages option, you can add Puppet modules with --puppet-modules, or errata with --errata-ids (see Example 3.8, “Adding Errata to a Content View using an Incremental Update”). For more information on working with incremental updates issue hammer content-view version incremental-update --help.

Example 3.8. Adding Errata to a Content View using an Incremental Update

This example shows how to apply an erratum to a host (named auth01.example.com) by creating an incremental update of its Content View:

$ hammer content-view version incremental-update \
--content-view-version-id 4 \
--errata-ids 8c3801f6-12a7-4a62-83f4-addbb1f34ce6 \
--lifecycle-environments Infrastructure

To find the required information for the above command, perform the following steps:

  1. Find the Content View your host is registered to as well as its life cycle environment by executing:

    $ hammer content-host info --name auth01.example.com --organization $ORG
  2. Then find the current version of the Content View (assuming Content View name RHEL7_Infra):

    $ hammer content-view info --name "RHEL7_Infra" --organization $ORG
  3. Find the IDs of errata you want to apply in the list of applicable errata in Library:

    $ hammer erratum list --content-view "RHEL7_Infra" --organization $ORG
    $ hammer host errata list --host auth01.example.com