Skip to content

Commit

Permalink
add registration_command module
Browse files Browse the repository at this point in the history
Fixes: #1284
  • Loading branch information
evgeni committed Nov 16, 2023
1 parent d15a7f2 commit 39132bb
Show file tree
Hide file tree
Showing 6 changed files with 486 additions and 0 deletions.
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ action_groups:
- puppet_environment
- puppetclasses_import
- realm
- registration_command
- repository
- repository_info
- repository_set
Expand Down
194 changes: 194 additions & 0 deletions plugins/modules/registration_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) Evgeni Golov
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = '''
---
module: registration_command
version_added: 4.0.0
short_description: Manage Registration Command
description:
- Manage Registration Command
author:
- "Evgeni Golov (@evgeni)"
options:
activation_keys:
description:
- Activation keys for subscription-manager client, required for CentOS and Red Hat
Enterprise Linux.
- Required only if host group has no activation keys.
required: false
type: list
elements: str
force:
description:
- "Clear any previous registration and run C(subscription-manager) with C(--force)."
required: false
type: bool
hostgroup:
description:
- Host group to register the host in
required: false
type: str
ignore_subman_errors:
description:
- Ignore C(subscription-manager) errors for C(subscription-manager register) command
required: false
type: bool
insecure:
description:
- Enable insecure argument for the initial C(curl)
required: false
type: bool
jwt_expiration:
description:
- Expiration of the authorization token (in hours)
required: false
type: int
lifecycle_environment:
description:
- Lifecycle environment for the host.
required: false
type: str
operatingsystem:
description:
- Operating System to register the host in.
- Operating system must have a C(host_init_config) template assigned.
required: false
type: str
packages:
description:
- Packages to install on the host when registered.
required: false
type: str
remote_execution_interface:
description:
- Identifier of the Host interface for Remote execution
required: false
type: str
repo:
description:
- Repository URL (yum/dnf) or full sources.list entry (apt).
required: false
type: str
repo_gpg_key_url:
description:
- URL of the GPG key for the repository
required: false
type: str
setup_insights:
description:
- If this is set to C(true), insights client will be installed
and registered on Red Hat family operating systems.
required: false
type: bool
setup_remote_execution:
description:
- If this is set to true, SSH keys will be installed on the host.
required: false
type: bool
setup_remote_execution_pull:
description:
- If this is set to true, pull provider client will be deployed on the host.
required: false
type: bool
smart_proxy:
description:
- Name of Smart Proxy.
- This Proxy must have both the C(Templates) and C(Registration) features enabled.
required: false
type: str
update_packages:
description:
- Update all packages on the host
required: false
type: bool
organization:
description:
- Organization to register the host in
required: false
type: str
location:
description:
- Location to register the host in
required: false
type: str
extends_documentation_fragment:
- theforeman.foreman.foreman
'''

EXAMPLES = '''
'''

RETURN = '''
registration_command:
description: The generated registration command.
returned: success
type: str
'''

from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanAnsibleModule


class ForemanRegistrationCommandModule(ForemanAnsibleModule):
pass


def main():
module = ForemanRegistrationCommandModule(
foreman_spec=dict(
hostgroup=dict(required=False, type='entity'),
operatingsystem=dict(required=False, type='entity'),
smart_proxy=dict(required=False, type='entity'),
setup_insights=dict(required=False, type='bool'),
setup_remote_execution=dict(required=False, type='bool'),
jwt_expiration=dict(required=False, type='int'),
insecure=dict(required=False, type='bool'),
packages=dict(required=False, type='str'),
update_packages=dict(required=False, type='bool'),
repo=dict(required=False, type='str'),
repo_gpg_key_url=dict(required=False, type='str', no_log=False),
remote_execution_interface=dict(required=False, type='str'),
setup_remote_execution_pull=dict(required=False, type='bool'),
activation_keys=dict(required=False, type='list', elements='str', no_log=False),
lifecycle_environment=dict(required=False, type='entity'),
force=dict(required=False, type='bool'),
ignore_subman_errors=dict(required=False, type='bool'),
organization=dict(type='entity'),
location=dict(type='entity'),
),
required_plugins=[
('katello', ['activation_key', 'activation_keys', 'lifecycle_environment', 'ignore_subman_errors', 'force']),
('remote_execution', ['remote_execution_interface', 'setup_remote_execution_pull']),
],
)

with module.api_connection():
module.auto_lookup_entities()
if not module.check_mode:
command = module.ensure_entity('registration_commands', module.foreman_params, None, state='present')['registration_command']
else:
command = "curl | bash"
module.exit_json(registration_command=command)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions tests/fixtures/apidoc/registration_command.json
Loading

0 comments on commit 39132bb

Please sign in to comment.