In this blog post, I’m going to practice publishing and promoting content views using the hammer CLI. I already know how to do this using the Satellite/Foreman web UI.

First, I’m going to create the Base content view for Operations organization and Boston location.

[root@foreman ~]# hammer content-view create \
> --name Base --organization Operations \
> --description 'Base Packages'
Content view created.

[root@foreman ~]# hammer content-view list --organization Operations
----------------|---------------------------|--------------------------|-----------|---------------------|---------------
CONTENT VIEW ID | NAME                      | LABEL                    | COMPOSITE | LAST PUBLISHED      | REPOSITORY IDS
----------------|---------------------------|--------------------------|-----------|---------------------|---------------
6               | Base                      | Base                     | false     |                     |
----------------|---------------------------|--------------------------|-----------|---------------------|---------------

The next step is adding the repos to the content view. I want to add the CentOS 8 BaseOS repo.

[root@foreman ~]# hammer repository list --organization Operations
---|-------------------------|---------------------|--------------|-----------------------------------------------------------------
ID | NAME                    | PRODUCT             | CONTENT TYPE | URL
---|-------------------------|---------------------|--------------|-----------------------------------------------------------------
61 | Admin Tools             | Custom Software     | yum          |
63 | AppStream               | CentOS 8 for x86_64 | yum          | http://mirror.internode.on.net/pub/centos/8/AppStream/x86_64/os/
62 | CentOS 8 BaseOS x86_64  | CentOS 8 for x86_64 | yum          | http://mirror.internode.on.net/pub/centos/8/BaseOS/x86_64/os/
60 | EPEL8 Everything x86_64 | EPEL8               | yum          | http://mirror.internode.on.net/pub/epel/8/Everything/x86_64/
---|-------------------------|---------------------|--------------|-----------------------------------------------------------------

To add a repository to the content view, 3 things are required: the name of the content view, the repos ID.

[root@foreman ~]# hammer content-view add-repository --name Base \
> --organization Operations \
> --repository-id 62
The repository has been associated.

At this point, I want to publish this Base contenview and promote it to the Development life-cycle environment.

[root@foreman ~]# hammer content-view publish --help
Usage:
    hammer content-view publish [OPTIONS]

Options:
 --async                                 Do not wait for the task
 --description DESCRIPTION               Description for the new published content view version
 --id ID                                 Content view identifier
 --major MAJOR                           Override the major version number
 --minor MINOR                           Override the minor version number
 --name NAME                             Content view name to search by
 --organization ORGANIZATION_NAME        Organization name to search by
 --organization-id ORGANIZATION_ID       Organization ID to search by
 --organization-label ORGANIZATION_LABEL Organization label to search by
 --repos-units REPOS_UNITS               Specify the list of units in each repo
                                         Comma separated list of values defined by a schema. See Option details section below.
                                         JSON is acceptable and preferred way for complex parameters
 -h, --help                              Print help

Option details:
  Following parameters accept format defined by its schema (bold are required; <> contain acceptable type; [] contain acceptable value):

  --repos-units       "label=<string>\,rpm_filenames=<array>, ... "

[root@foreman ~]# hammer content-view list --organization Operations
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
CONTENT VIEW ID | NAME                      | LABEL                                | COMPOSITE | LAST PUBLISHED      | REPOSITORY IDS
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
6               | Base                      | Base                                 | false     |                     | 62
5               | Default Organization View | 11ae06b0-6db1-4ce6-8254-5ff13598df7a | false     | 2021/03/07 03:44:58 |
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
[root@foreman ~]# hammer content-view publish \
> --id 6 --organization Operations \
> --description 'Base Repositories'
[..............................................................................................................................] [100%]

To promote the above published content view to Development life-cycle environment, I’m going to need a few important information: content view ID|name, from environment ID, to environment ID, content view’s version ID.

[root@foreman ~]# hammer content-view version list --organization Operations
---|-------------------------------|---------|-------------------|-----------------------
ID | NAME                          | VERSION | DESCRIPTION       | LIFECYCLE ENVIRONMENTS
---|-------------------------------|---------|-------------------|-----------------------
10 | Base 1.0                      | 1.0     | Base Repositories | Library
8  | Default Organization View 1.0 | 1.0     |                   | Library
---|-------------------------------|---------|-------------------|-----------------------


[root@foreman ~]# hammer content-view list --organization Operations
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
CONTENT VIEW ID | NAME                      | LABEL                                | COMPOSITE | LAST PUBLISHED      | REPOSITORY IDS
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------
6               | Base                      | Base                                 | false     | 2021/03/07 13:08:50 | 62
5               | Default Organization View | 11ae06b0-6db1-4ce6-8254-5ff13598df7a | false     | 2021/03/07 03:44:58 |
----------------|---------------------------|--------------------------------------|-----------|---------------------|---------------

[root@foreman ~]# hammer lifecycle-environment list --organization Operations
---|-------------|------------
ID | NAME        | PRIOR
---|-------------|------------
7  | Development | Library
6  | Library     |
9  | Production  | QA
8  | QA          | Development
---|-------------|------------

With the above information, we’re ready to the promote the Base content view.

[root@foreman ~]# hammer content-view version promote \
--id 10 \
--content-view-id 6 \
--lifecycle-environment-ids 6 \
--to-lifecycle-environment-id 7 \
--description 'Base Repositories' --version 1.0 \
--organization Operations
[..............................................................................................................................] [100%]

[root@foreman ~]# hammer content-view version list --organization Operations
---|-------------------------------|---------|-------------------|-----------------------
ID | NAME                          | VERSION | DESCRIPTION       | LIFECYCLE ENVIRONMENTS
---|-------------------------------|---------|-------------------|-----------------------
10 | Base 1.0                      | 1.0     | Base Repositories | Library, Development
8  | Default Organization View 1.0 | 1.0     |                   | Library
---|-------------------------------|---------|-------------------|-----------------------

(At this point, I think it’s a bit faster to use the Web UI to promote the content view.)

Well, let’s learn how to modify the Base content view by including the EPEL 8 repository. When done, promote this new version to the Deveopment life-cycle.

As usual, I’m going to find out run some commands to look up some required IDs.

[root@foreman ~]# hammer organization list
---|----------------------|----------------------|-------------|---------------------
ID | TITLE                | NAME                 | DESCRIPTION | LABEL
---|----------------------|----------------------|-------------|---------------------
1  | Default Organization | Default Organization |             | Default_Organization
3  | Finance              | Finance              |             | Finance
5  | Operations           | Operations           |             | Operations
---|----------------------|----------------------|-------------|---------------------
[root@foreman ~]# hammer repository list --organization-id 5 --product EPEL8
---|-------------------------|---------|--------------|-------------------------------------------------------------
ID | NAME                    | PRODUCT | CONTENT TYPE | URL
---|-------------------------|---------|--------------|-------------------------------------------------------------
60 | EPEL8 Everything x86_64 | EPEL8   | yum          | http://mirror.internode.on.net/pub/epel/8/Everything/x86_64/
---|-------------------------|---------|--------------|-------------------------------------------------------------
[root@foreman ~]# hammer content-view add-repository --organization-id 5 \
> --product EPEL8 \
> --repository-id 60 \
> --name Base
The repository has been associated.

You know what, let’s add the CentOS 8 AppStream repo to the Base content-view too.

[root@foreman ~]# hammer repository list --organization-id 5
---|-------------------------|---------------------|--------------|-----------------------------------------------------------------
ID | NAME                    | PRODUCT             | CONTENT TYPE | URL
---|-------------------------|---------------------|--------------|-----------------------------------------------------------------
61 | Admin Tools             | Custom Software     | yum          |
63 | AppStream               | CentOS 8 for x86_64 | yum          | http://mirror.internode.on.net/pub/centos/8/AppStream/x86_64/os/
62 | CentOS 8 BaseOS x86_64  | CentOS 8 for x86_64 | yum          | http://mirror.internode.on.net/pub/centos/8/BaseOS/x86_64/os/
60 | EPEL8 Everything x86_64 | EPEL8               | yum          | http://mirror.internode.on.net/pub/epel/8/Everything/x86_64/
---|-------------------------|---------------------|--------------|-----------------------------------------------------------------
[root@foreman ~]# hammer content-view add-repository --organization-id 5 --product 'CentOS 8 for x86_64' --repository-id 63 --name Base
The repository has been associated.

Let’s publish the content view.

[root@foreman ~]# hammer content-view publish \
> --id 6 \
> --organization-id 5 \
> --description 'Base Repositories Version 2'
[............................................................................................................................] [100%]
[root@foreman ~]# hammer content-view version list --organization Operations
---|-------------------------------|---------|-----------------------------|-----------------------
ID | NAME                          | VERSION | DESCRIPTION                 | LIFECYCLE ENVIRONMENTS
---|-------------------------------|---------|-----------------------------|-----------------------
11 | Base 2.0                      | 2.0     | Base Repositories Version 2 | Library
10 | Base 1.0                      | 1.0     | Base Repositories           | Development
8  | Default Organization View 1.0 | 1.0     |                             | Library
---|-------------------------------|---------|-----------------------------|-----------------------
[root@foreman ~]# hammer content-view version promote --id 11 \
--content-view-id 6 --lifecycle-environment-ids 6 --to-lifecycle-environment-id 7 \
--description 'Base Repositories' --organization Operations
[............................................................................................................................] [100%]

[root@foreman ~]# hammer content-view version list --organization Operations
---|-------------------------------|---------|-----------------------------|-----------------------
ID | NAME                          | VERSION | DESCRIPTION                 | LIFECYCLE ENVIRONMENTS
---|-------------------------------|---------|-----------------------------|-----------------------
11 | Base 2.0                      | 2.0     | Base Repositories Version 2 | Library, Development
10 | Base 1.0                      | 1.0     | Base Repositories           |
8  | Default Organization View 1.0 | 1.0     |                             | Library
---|-------------------------------|---------|-----------------------------|-----------------------

I can stop here. But wait, let’s promote the Base Version 2.0 content view to QA life-cycle environment.

[root@foreman ~]# hammer lifecycle-environment list --organization-id 5
---|-------------|------------
ID | NAME        | PRIOR
---|-------------|------------
7  | Development | Library
6  | Library     |
9  | Production  | QA
8  | QA          | Development
---|-------------|------------

[root@foreman ~]# hammer content-view version promote --id 11 --content-view-id 6 \
--lifecycle-environment-ids 7 --to-lifecycle-environment-id 8 \
--description 'Base Repositories v2' --organization-id 5
[..........................................................................................................................] [100%]

That’s it. This blog post is quite long, and it should be because I’m practicing how to use hammer CLI to work on tasks which can be easily done on the Foreman/Satellite web UI.

Here is a take away if you’ve read this far. hammer has a very useful help system, you can pass --help if you cannot remember any command options.