Feedback wanted - Hammer CLI Foreman Admin tool

Hello,

I released the initial version of hammer foreman CLI admin tool which aims to
deliver a common platform for various administrative server tasks. We have
currently various scripts which can be now turned into subcommands. Leveraging
our hammer CLI gives us benefits like logging, i18n, command line parsing and
others.

The initial (and only) implemented admin command is currently "logging"
which was a request coming from Red Hat Support team to enable Foreman
users to switch debugging mode for all or individual components. This
can be used for troubleshooting and debugging. The tool works both on
Foreman server and Proxy, it detects components (services) via
configuration file existence.

I will be working on OS distribution packages next week, but in the
meantime I would like to gather your comments and feedback on this tool.
To test it with Foreman 1.11+ (or Satellite 6.2+ beta), issue the
following commands:

wget https://rubygems.org/downloads/hammer_cli_foreman_admin-0.0.1.gem
scl enable tfm "gem install hammer_cli_foreman_admin-0.0.1.gem"
echo -e ":foreman_admin:\n :enable_module: true" > /etc/hammer/cli.modules.d/foreman_admin.yml

skip this when using Foreman nightly build

wget https://github.com/theforeman/hammer-cli/pull/201.patch
patch -p1 -t -d /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-* < 201.patch

The above patch command will skip one hunk (unit tests) which is
expected and you can ignore it. Also, this path will only work on RHEL.
On Debian systems it is different.

Example use:

hammer admin logging -h

Usage:
hammer admin logging [OPTIONS]

Options:
–no-backup Skip configuration backups creation.
–prefix PATH Operate on prefixed environment (e.g. chroot).
-a, --all Apply to all components.
-c, --components COMPONENTS Components to apply, use --list to get them.
Comma separated list of values.
-d, --level-debug Increase verbosity level to debug.
-h, --help print help
-l, --list List available components.
-n, --dry-run Do not apply specified changes.
-p, --level-production Decrease verbosity level to standard.

hammer admin logging --list

---------------|------------------------------------

COMPONENT NAME AUTO-DETECTED BY EXISTENCE OF
postgresql /var/lib/pgsql/data/postgresql.conf
rails /etc/foreman/settings.yaml
proxy /etc/foreman-proxy/settings.yml
puppet /etc/puppet/puppet.conf
dhcpd /etc/dhcp/dhcpd.conf
named /etc/named.conf
tftp /etc/xinetd.d/tftp
mongod /etc/mongod.conf
qpidd /etc/qpid/qpidd.conf
tomcat /etc/candlepin/candlepin.conf
pulp /etc/pulp/server.conf
virt-who /etc/sysconfig/virt-who
--------------- ------------------------------------

hammer admin logging --level-debug --all

The command is silent by default following UNIX principles, if you want
to see what is going on add debug option (verbose option is currently
broken in hammer cli core not providing possibility to hook on it -
issue filed).

hammer -d admin logging --level-debug --all

Initialization of Hammer CLI (0.5.1.5) has started…

Called with options: {"option_level_debug"=>true, "option_all"=>true}
Processing postgresql action ensure_line_is_present
Creating backup /var/lib/pgsql/data/postgresql.conf.o6ar52~
Processing postgresql action ensure_line_is_present
Creating backup /var/lib/pgsql/data/postgresql.conf.o6ar52~
Processing postgresql action ensure_line_is_present
Creating backup /var/lib/pgsql/data/postgresql.conf.o6ar52~
Processing rails action run_command_on_file
Creating backup /etc/foreman/settings.yaml.o6ar52~
Processing proxy action ensure_line_is_present
Creating backup /etc/foreman-proxy/settings.yml.o6ar52~
Processing puppet action ensure_line_is_present
Creating backup /etc/puppet/puppet.conf.o6ar52~
Processing dhcpd action create_file
Creating backup /etc/dhcp/dhcpd.conf.o6ar52~
Processing dhcpd action ensure_line_is_present
Creating backup /etc/dhcp/dhcpd.conf.o6ar52~
Processing named action run_command
Creating backup /etc/named.conf.o6ar52~
Processing tftp action ensure_line_is_present
Creating backup /etc/xinetd.d/tftp.o6ar52~
Processing mongod action ensure_line_is_present
Creating backup /etc/mongod.conf.o6ar52~
Processing qpidd action ensure_line_is_present
Creating backup /etc/qpid/qpidd.conf.o6ar52~
Processing tomcat action ensure_line_is_present
Creating backup /etc/candlepin/candlepin.conf.o6ar52~
Processing pulp action create_file
Creating backup /etc/pulp/server.conf.o6ar52~
Processing pulp action ensure_line_is_present
Creating backup /etc/pulp/server.conf.o6ar52~
Skipped component virt-who, file /etc/sysconfig/virt-who does not exist

Then restart all services, when using Katello you can do this by:

katello-service restart

To put things back into initial state simply issue:

hammer admin logging --level-production --all

You can use diff tool to compare against backup versions, but to save
you the time, the diffs are here:

If you want to get rid of this gem, issue the following commands:

scl enable tfm "gem uninstall hammer_cli_foreman_admin"
rm /etc/hammer/cli.modules.d/foreman_admin.yml
patch -p1 -R -t -d /opt/theforeman/tfm/root/usr/share/gems/gems/hammer_cli-* < 201.patch

Thanks for your feedback!

··· -- Later, Lukas #lzap Zapletal