Skip to content

Commit

Permalink
CLI can manage ansible roles on host(group)s
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren committed Apr 11, 2018
1 parent c290ed9 commit d7f179f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
19 changes: 19 additions & 0 deletions lib/hammer_cli_foreman_ansible.rb
@@ -1,13 +1,32 @@
module HammerCLIForemanAnsible
require 'hammer_cli_foreman'
require 'hammer_cli_foreman/host'
require 'hammer_cli_foreman/hostgroup'

require 'hammer_cli_foreman_ansible/version'
require 'hammer_cli_foreman_ansible/i18n'
require 'hammer_cli_foreman_ansible/ansible'
require 'hammer_cli_foreman_ansible/base'
require 'hammer_cli_foreman_ansible/ansible_roles'
require 'hammer_cli_foreman_ansible/host'
require 'hammer_cli_foreman_ansible/hostgroup'

HammerCLI::MainCommand.lazy_subcommand(
'ansible',
'Manage foreman ansible',
'HammerCLIForemanAnsible::AnsibleCommand',
'hammer_cli_foreman_ansible/ansible'
)
HammerCLIForeman::Host.lazy_subcommand(
HostAnsibleRolesCommand.command_name,
HostAnsibleRolesCommand.desc,
'HammerCLIForemanAnsible::HostAnsibleRolesCommand',
'hammer_cli_foreman_ansible/host'
)
HammerCLIForeman::Hostgroup.lazy_subcommand(
HostgroupAnsibleRolesCommand.command_name,
HostgroupAnsibleRolesCommand.desc,
'HammerCLIForemanAnsible::HostgroupAnsibleRolesCommand',
'hammer_cli_foreman_ansible/hostgroup'
)
end
8 changes: 2 additions & 6 deletions lib/hammer_cli_foreman_ansible/ansible_roles.rb
Expand Up @@ -3,16 +3,12 @@ class AnsibleRolesCommand < HammerCLIForeman::Command
resource :ansible_roles

class InfoCommand < HammerCLIForeman::InfoCommand
output do
field :id, _('Id')
field :name, _('Name')
field :created_at, _('Imported at')
end
output BaseAnsibleRolesCommand.output_definition
build_options
end

class ListCommand < HammerCLIForeman::ListCommand
output HammerCLIForemanAnsible::AnsibleRolesCommand::InfoCommand.output_definition
output AnsibleRolesCommand::InfoCommand.output_definition
build_options
end

Expand Down
18 changes: 18 additions & 0 deletions lib/hammer_cli_foreman_ansible/base.rb
@@ -0,0 +1,18 @@
module HammerCLIForemanAnsible
class BaseAnsibleRolesCommand < HammerCLIForeman::Command
command_name 'ansible-roles'
desc _('List all Ansible roles')

action :ansible_roles

output do
field :id, _('Id'), Fields::Id
field :name, _('Name')
field :created_at, _('Imported at'), Fields::Date
end

def adapter
:table
end
end
end
6 changes: 6 additions & 0 deletions lib/hammer_cli_foreman_ansible/host.rb
@@ -0,0 +1,6 @@
module HammerCLIForemanAnsible
class HostAnsibleRolesCommand < BaseAnsibleRolesCommand
resource :hosts
build_options
end
end
6 changes: 6 additions & 0 deletions lib/hammer_cli_foreman_ansible/hostgroup.rb
@@ -0,0 +1,6 @@
module HammerCLIForemanAnsible
class HostgroupAnsibleRolesCommand < BaseAnsibleRolesCommand
resource :hostgroups
build_options
end
end

0 comments on commit d7f179f

Please sign in to comment.