| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from __future__ import absolute_import, division, print_function |
| 19 |
__metaclass__ = type |
| 20 |
|
| 21 |
|
| 22 |
DOCUMENTATION = ''' |
| 23 |
--- |
| 24 |
module: registration_command |
| 25 |
version_added: 4.0.0 |
| 26 |
short_description: Manage Registration Command |
| 27 |
description: |
| 28 |
- Manage Registration Command |
| 29 |
author: |
| 30 |
- "Evgeni Golov (@evgeni)" |
| 31 |
options: |
| 32 |
activation_keys: |
| 33 |
description: |
| 34 |
- Activation keys for subscription-manager client, required for CentOS and Red Hat |
| 35 |
Enterprise Linux. |
| 36 |
- Required only if host group has no activation keys. |
| 37 |
required: false |
| 38 |
type: list |
| 39 |
elements: str |
| 40 |
force: |
| 41 |
description: |
| 42 |
- "Clear any previous registration and run C(subscription-manager) with C(--force)." |
| 43 |
required: false |
| 44 |
type: bool |
| 45 |
hostgroup: |
| 46 |
description: |
| 47 |
- Host group to register the host in. |
| 48 |
required: false |
| 49 |
type: str |
| 50 |
ignore_subman_errors: |
| 51 |
description: |
| 52 |
- Ignore C(subscription-manager) errors for C(subscription-manager register) command. |
| 53 |
required: false |
| 54 |
type: bool |
| 55 |
insecure: |
| 56 |
description: |
| 57 |
- Enable insecure argument for the initial C(curl). |
| 58 |
required: false |
| 59 |
type: bool |
| 60 |
jwt_expiration: |
| 61 |
description: |
| 62 |
- Expiration of the authorization token (in hours). |
| 63 |
required: false |
| 64 |
type: int |
| 65 |
lifecycle_environment: |
| 66 |
description: |
| 67 |
- Lifecycle environment for the host. |
| 68 |
- "Deprecated: The Lifecycle Environment of a Host should be set by the Activation Key." |
| 69 |
- Removed from the API since Katello 4.12. |
| 70 |
required: false |
| 71 |
type: str |
| 72 |
operatingsystem: |
| 73 |
description: |
| 74 |
- Operating System to register the host in. |
| 75 |
- Operating system must have a C(host_init_config) template assigned. |
| 76 |
required: false |
| 77 |
type: str |
| 78 |
packages: |
| 79 |
description: |
| 80 |
- Packages to install on the host when registered. |
| 81 |
- Multiple packages are to be given as a space delimited string. |
| 82 |
required: false |
| 83 |
type: str |
| 84 |
remote_execution_interface: |
| 85 |
description: |
| 86 |
- Identifier of the Host interface for Remote execution. |
| 87 |
required: false |
| 88 |
type: str |
| 89 |
repo: |
| 90 |
description: |
| 91 |
- Repository URL (yum/dnf) or full sources.list entry (apt). |
| 92 |
- "Deprecated: Use the I(repo_data) option instead. This option was deprecated in version Foreman 3.11." |
| 93 |
required: false |
| 94 |
type: str |
| 95 |
repo_gpg_key_url: |
| 96 |
description: |
| 97 |
- URL of the GPG key for the repository. |
| 98 |
- "Deprecated: Use the I(repo_data) option instead. This option was deprecated in version Foreman 3.11." |
| 99 |
required: false |
| 100 |
type: str |
| 101 |
repo_data: |
| 102 |
description: |
| 103 |
- Array with repository URL and corresponding GPG key URL. |
| 104 |
- Each element is a dictionary with keys C(repo) and C(repo_gpg_key_url). |
| 105 |
required: false |
| 106 |
type: list |
| 107 |
elements: dict |
| 108 |
suboptions: |
| 109 |
repo: |
| 110 |
description: |
| 111 |
- Repository URL or details (e.g., "deb http://deb.example.com/ buster 1.0" for Debian, "https://yum.example.com/el8/x86_64/ " for Red Hat/SUSE). |
| 112 |
required: true |
| 113 |
type: str |
| 114 |
repo_gpg_key_url: |
| 115 |
description: |
| 116 |
- URL of the GPG key for the repository. |
| 117 |
required: false |
| 118 |
type: str |
| 119 |
setup_insights: |
| 120 |
description: |
| 121 |
- If this is set to C(true), C(insights-client) will be installed |
| 122 |
and registered on Red Hat family operating systems. |
| 123 |
required: false |
| 124 |
type: bool |
| 125 |
setup_remote_execution: |
| 126 |
description: |
| 127 |
- If this is set to true, SSH keys will be installed on the host. |
| 128 |
required: false |
| 129 |
type: bool |
| 130 |
setup_remote_execution_pull: |
| 131 |
description: |
| 132 |
- If this is set to true, pull provider client will be deployed on the host. |
| 133 |
required: false |
| 134 |
type: bool |
| 135 |
setup_container_registry_certs: |
| 136 |
description: |
| 137 |
- If this is set to C(true), container registry certificates will be installed on the host. |
| 138 |
required: false |
| 139 |
type: bool |
| 140 |
version_added: 5.11.0 |
| 141 |
smart_proxy: |
| 142 |
description: |
| 143 |
- Name of Smart Proxy. |
| 144 |
- This Proxy must have both the C(Templates) and C(Registration) features enabled. |
| 145 |
required: false |
| 146 |
type: str |
| 147 |
update_packages: |
| 148 |
description: |
| 149 |
- Update all packages on the host. |
| 150 |
required: false |
| 151 |
type: bool |
| 152 |
organization: |
| 153 |
description: |
| 154 |
- Organization to register the host in. |
| 155 |
required: false |
| 156 |
type: str |
| 157 |
location: |
| 158 |
description: |
| 159 |
- Location to register the host in. |
| 160 |
required: false |
| 161 |
type: str |
| 162 |
|
| 163 |
extends_documentation_fragment: |
| 164 |
- theforeman.foreman.foreman |
| 165 |
''' |
| 166 |
|
| 167 |
EXAMPLES = ''' |
| 168 |
# This needs to run on a host with API access |
| 169 |
- name: "Generate registration command" |
| 170 |
theforeman.foreman.registration_command: |
| 171 |
username: "admin" |
| 172 |
password: "changeme" |
| 173 |
server_url: "https://foreman.example.com" |
| 174 |
register: command |
| 175 |
delegate_to: localhost |
| 176 |
|
| 177 |
# This needs to run on the host being registered |
| 178 |
- name: "Perform registration" |
| 179 |
ansible.builtin.shell: |
| 180 |
cmd: "{{ command.registration_command }}" |
| 181 |
''' |
| 182 |
|
| 183 |
RETURN = ''' |
| 184 |
registration_command: |
| 185 |
description: The generated registration command. |
| 186 |
returned: success |
| 187 |
type: str |
| 188 |
''' |
| 189 |
|
| 190 |
from ansible_collections.theforeman.foreman.plugins.module_utils.foreman_helper import ForemanAnsibleModule |
| 191 |
|
| 192 |
|
| 193 |
class ForemanRegistrationCommandModule(ForemanAnsibleModule): |
| 194 |
pass |
| 195 |
|
| 196 |
|
| 197 |
def main(): |
| 198 |
module = ForemanRegistrationCommandModule( |
| 199 |
foreman_spec=dict( |
| 200 |
hostgroup=dict(type='entity'), |
| 201 |
operatingsystem=dict(type='entity'), |
| 202 |
smart_proxy=dict(type='entity'), |
| 203 |
setup_insights=dict(type='bool'), |
| 204 |
setup_remote_execution=dict(type='bool'), |
| 205 |
jwt_expiration=dict(type='int'), |
| 206 |
insecure=dict(type='bool'), |
| 207 |
packages=dict(type='str'), |
| 208 |
update_packages=dict(type='bool'), |
| 209 |
repo=dict(type='str'), |
| 210 |
repo_gpg_key_url=dict(type='str', no_log=False), |
| 211 |
repo_data=dict(type='list', elements='dict', options=dict( |
| 212 |
repo=dict(type='str', required=True), |
| 213 |
repo_gpg_key_url=dict(type='str', no_log=False), |
| 214 |
)), |
| 215 |
remote_execution_interface=dict(type='str'), |
| 216 |
setup_remote_execution_pull=dict(type='bool'), |
| 217 |
setup_container_registry_certs=dict(type='bool'), |
| 218 |
activation_keys=dict(type='list', elements='str', no_log=False), |
| 219 |
lifecycle_environment=dict(type='entity'), |
| 220 |
force=dict(type='bool'), |
| 221 |
ignore_subman_errors=dict(type='bool'), |
| 222 |
organization=dict(type='entity'), |
| 223 |
location=dict(type='entity'), |
| 224 |
), |
| 225 |
required_plugins=[ |
| 226 |
('katello', ['activation_key', 'activation_keys', 'lifecycle_environment', 'ignore_subman_errors', 'force', 'setup_container_registry_certs']), |
| 227 |
('remote_execution', ['remote_execution_interface', 'setup_remote_execution_pull']), |
| 228 |
], |
| 229 |
) |
| 230 |
|
| 231 |
with module.api_connection(): |
| 232 |
module.auto_lookup_entities() |
| 233 |
if not module.check_mode: |
| 234 |
command = module.ensure_entity('registration_commands', module.foreman_params, None, state='present')['registration_command'] |
| 235 |
else: |
| 236 |
command = "curl | bash" |
| 237 |
module.exit_json(registration_command=command) |
| 238 |
|
| 239 |
|
| 240 |
if __name__ == '__main__': |
| 241 |
main() |