mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
rhsm modules: cleanly fail when not run as root (#6211)
subscription-manager on RHEL installs a symlink in /usr/bin to console-helper (part of usermode), which triggers an interactive prompt for root credentials when run as user. It seems that console-helper does not handle well non-interactive contexts (e.g. without a TTY for input), and thus it will hang waiting for input when run as user in an Ansible task. Since subscription-manager requires root already anyway (and it will fail when explicitly run as user), then apply the same logic locally on all the modules that interact with it: redhat_subscription, rhsm_release, and rhsm_repository.
This commit is contained in:
parent
512bf4b77f
commit
9f67cbbe36
6 changed files with 40 additions and 4 deletions
|
@ -24,6 +24,8 @@ notes:
|
|||
I(server_proxy_hostname), I(server_proxy_port), I(server_proxy_user) and
|
||||
I(server_proxy_password) are no longer taken from the C(/etc/rhsm/rhsm.conf)
|
||||
config file and default to None.
|
||||
- It is possible to interact with C(subscription-manager) only as root,
|
||||
so root permissions are required to successfully run this module.
|
||||
requirements:
|
||||
- subscription-manager
|
||||
- Optionally the C(dbus) Python library; this is usually included in the OS
|
||||
|
@ -291,7 +293,7 @@ subscribed_pool_ids:
|
|||
'''
|
||||
|
||||
from os.path import isfile
|
||||
from os import unlink
|
||||
from os import getuid, unlink
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
|
@ -1074,6 +1076,11 @@ def main():
|
|||
required_if=[['state', 'present', ['username', 'activationkey', 'token'], True]],
|
||||
)
|
||||
|
||||
if getuid() != 0:
|
||||
module.fail_json(
|
||||
msg="Interacting with subscription-manager requires root permissions ('become: true')"
|
||||
)
|
||||
|
||||
rhsm.module = module
|
||||
state = module.params['state']
|
||||
username = module.params['username']
|
||||
|
|
|
@ -18,6 +18,8 @@ notes:
|
|||
- This module will fail on an unregistered system.
|
||||
Use the C(redhat_subscription) module to register a system
|
||||
prior to setting the RHSM release.
|
||||
- It is possible to interact with C(subscription-manager) only as root,
|
||||
so root permissions are required to successfully run this module.
|
||||
requirements:
|
||||
- Red Hat Enterprise Linux 6+ with subscription-manager installed
|
||||
extends_documentation_fragment:
|
||||
|
@ -63,6 +65,7 @@ current_release:
|
|||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
# Matches release-like values such as 7.2, 5.10, 6Server, 8
|
||||
|
@ -109,6 +112,11 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
if os.getuid() != 0:
|
||||
module.fail_json(
|
||||
msg="Interacting with subscription-manager requires root permissions ('become: true')"
|
||||
)
|
||||
|
||||
target_release = module.params['release']
|
||||
|
||||
# sanity check: the target release at least looks like a valid release
|
||||
|
|
|
@ -19,6 +19,8 @@ author: Giovanni Sciortino (@giovannisciortino)
|
|||
notes:
|
||||
- In order to manage RHSM repositories the system must be already registered
|
||||
to RHSM manually or using the Ansible C(redhat_subscription) module.
|
||||
- It is possible to interact with C(subscription-manager) only as root,
|
||||
so root permissions are required to successfully run this module.
|
||||
|
||||
requirements:
|
||||
- subscription-manager
|
||||
|
@ -100,9 +102,7 @@ def run_subscription_manager(module, arguments):
|
|||
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
|
||||
rc, out, err = module.run_command("%s %s" % (rhsm_bin, " ".join(arguments)), environ_update=lang_env)
|
||||
|
||||
if rc == 1 and (err == 'The password you typed is invalid.\nPlease try again.\n' or os.getuid() != 0):
|
||||
module.fail_json(msg='The executable file subscription-manager must be run using root privileges')
|
||||
elif rc == 0 and out == 'This system has no repositories available through subscriptions.\n':
|
||||
if rc == 0 and out == 'This system has no repositories available through subscriptions.\n':
|
||||
module.fail_json(msg='This system has no repositories available through subscriptions')
|
||||
elif rc == 1:
|
||||
module.fail_json(msg='subscription-manager failed with the following error: %s' % err)
|
||||
|
@ -243,6 +243,12 @@ def main():
|
|||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
if os.getuid() != 0:
|
||||
module.fail_json(
|
||||
msg="Interacting with subscription-manager requires root permissions ('become: true')"
|
||||
)
|
||||
|
||||
name = module.params['name']
|
||||
state = module.params['state']
|
||||
purge = module.params['purge']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue