Red Hat Satellite Server is a key tool in the provisioning process for the systems in our Labs. In one of our labs we have an older deployment running Satellite 6 which maps to the upstream project The Foreman version 1.11. Since I want to be able to perform repeatable operations on this server, I need to make Web API calls.
The easiest way to do this is to use the Hammer CLI. But it turns out the version of Hammer is somewhat tied to the version of Satellite server; the version I have in Fedora 27 Does not talk to this older Satellite instance. So, I want to run an older Hammer.
I decided to use this as an opportunity to walk through running an RPM managed application targetted for RHEL 6/EPEL 6 via Docker.
Edit: actually, this might not be the case, but the rest of the learning process was interesting enough that I kept working at it.
Edit2: This was necessary, see the bottom. Also, the 1.11 in the URL refers to the upstream repo for theforeman. I’d use a different repo for building using supported RH RPMs.
Here is what I learned.
It took some trial and error to get to the following Dockerfile
FROM index.docker.io/centos:6 MAINTAINER Adam Young <email@example.com> COPY foreman.repo /etc/yum.repos.d/ RUN yum -y install centos-release-scl yum-utils RUN yum-config-manager --enable rhel-server-rhscl-6-rpm RUN yum -y install rh-ruby22 RUN yum -y install tfm-rubygem-hammer_cli &&\ yum -y clean all CMD /usr/bin/hammer
The reason I have the separate RUN lines as opposed to using the &&\ line continuation technique is that I wanted a faster turnaround time for making changes;
With this docker file, I can build the image using
docker build -t hammer-cli .
And run the CLI using
docker run hammer-cli
which produces the output
Usage: hammer [OPTIONS] SUBCOMMAND [ARG] ... Parameters: SUBCOMMAND subcommand [ARG] ... subcommand arguments Subcommands: defaults Defaults management shell Interactive shell Options: --autocomplete LINE Get list of possible endings --csv Output as CSV (same as --output=csv) --csv-separator SEPARATOR Character to separate the values --interactive INTERACTIVE Explicitly turn interactive mode on/off One of true/false, yes/no, 1/0. --output ADAPTER Set output format. One of [base, table, silent, csv, yaml, json] --show-ids Show ids of associated resources --version show version -c, --config CFG_FILE path to custom config file -d, --debug show debugging output -h, --help print help -p, --password PASSWORD password to access the remote system -r, --reload-cache force reload of Apipie cache -s, --server SERVER remote system address -u, --username USERNAME username to access the remote system -v, --verbose be verbose
If I want to pass command line arguments to the command, I can override the entrypoint. To get help I can run:
docker run hammer-cli /usr/bin/hammer --help
But trying to run a non-trivial command seems to fail:
$ docker run hammer-cli /usr/bin/hammer host Error: No such sub-command 'host' See: 'hammer --help'
Perhaps I need additional plugins?
On a functioning system, I can run
hammer user list
And get a response. What other RPMS are on there:
$ rpmquery -a | grep hammer tfm-rubygem-hammer_cli-0.5.1.13-2.el7sat.noarch tfm-rubygem-hammer_cli_foreman_remote_execution-0.0.5.3-1.el7sat.noarch tfm-rubygem-hammer_cli_foreman_bootdisk-0.1.3.3-1.el7sat.noarch tfm-rubygem-hammer_cli_foreman_tasks-0.0.10.3-1.el7sat.noarch tfm-rubygem-hammer_cli_katello-0.0.22.29-1.el7sat.noarch tfm-rubygem-hammer_cli_foreman_discovery-0.0.2.3-1.el7sat.noarch tfm-rubygem-hammer_cli_import-0.11.2-1.el7sat.noarch tfm-rubygem-hammer_cli_csv-126.96.36.199-1.el7sat.noarch tfm-rubygem-hammer_cli_foreman_docker-0.0.6-1.el7sat.noarch tfm-rubygem-hammer_cli_foreman-0.5.1.10-1.el7sat.noarch tfm-rubygem-hammer_cli_foreman_admin-0.0.5-1.el7sat.noarch
Lets add these in to the docker file and see if it makes a difference;
After much trial and error, it turns out the issue is with a few things, including DNS. I did need the plugins above. I finally got the command to run like this:
docker run hammer-cli /usr/bin/hammer -p redacted -u tester -s https://10.3.76.6 host list
Here is my final dockerfile
FROM index.docker.io/centos:6 MAINTAINER Adam Young <firstname.lastname@example.org> COPY foreman.repo /etc/yum.repos.d/ RUN yum -y install centos-release-scl yum-utils RUN yum-config-manager --enable rhel-server-rhscl-6-rpm RUN yum -y install rh-ruby22 RUN yum -y install tfm-rubygem-hammer_cli \ tfm-rubygem-hammer_cli \ tfm-rubygem-hammer_cli_foreman_remote_execution \ tfm-rubygem-hammer_cli_foreman_bootdisk \ tfm-rubygem-hammer_cli_foreman_tasks \ tfm-rubygem-hammer_cli_katello \ tfm-rubygem-hammer_cli_foreman_discovery \ tfm-rubygem-hammer_cli_import \ tfm-rubygem-hammer_cli_csv \ tfm-rubygem-hammer_cli_foreman_docker \ tfm-rubygem-hammer_cli_foreman \ tfm-rubygem-hammer_cli_foreman_admin RUN yum -y clean all CMD /usr/bin/hammer
Edit: 2 so I DID need this version of Hammer, as the host create failed using the latest. I was able to createa host using the following command:
docker run hammer-cli /usr/bin/hammer \ -p redacted -u tester \ -s https://10.3.76.6 \ host create \ --name blade02 \ --architecture x86_64 \ --domain mydomain.net \ --operatingsystem "RedHat 7.4" \ --partition-table "Kickstart default" \ --location Phoenix \ --hostgroup "MYDOMAINHOSTGROUP" \ --interface="primary=true, \ mac=D8:D3:85:C3:3C:08" \ --organization DEMO \ --root-pass redacted