mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-16 09:55:26 -07:00
Use atomic_move rather than writing in place in redhat_subscription (#27132)
* Use atomic_move rather than writing in place in redhat_subscription and redhat utils * Change status to curated * Put curated in the proper field * Add RETURN doc section * Disable yum plugins when unregistering * Change back to community supported * Alphabetize imports
This commit is contained in:
parent
e8a396be16
commit
1c40631382
3 changed files with 50 additions and 11 deletions
|
@ -28,6 +28,8 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from ansible.module_utils.six.moves import configparser
|
from ansible.module_utils.six.moves import configparser
|
||||||
|
@ -59,16 +61,22 @@ class RegistrationBase(object):
|
||||||
|
|
||||||
def update_plugin_conf(self, plugin, enabled=True):
|
def update_plugin_conf(self, plugin, enabled=True):
|
||||||
plugin_conf = '/etc/yum/pluginconf.d/%s.conf' % plugin
|
plugin_conf = '/etc/yum/pluginconf.d/%s.conf' % plugin
|
||||||
|
|
||||||
if os.path.isfile(plugin_conf):
|
if os.path.isfile(plugin_conf):
|
||||||
|
tmpfd, tmpfile = tempfile.mkstemp()
|
||||||
|
shutil.copy2(plugin_conf, tmpfile)
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg.read([plugin_conf])
|
cfg.read([tmpfile])
|
||||||
|
|
||||||
if enabled:
|
if enabled:
|
||||||
cfg.set('main', 'enabled', 1)
|
cfg.set('main', 'enabled', 1)
|
||||||
else:
|
else:
|
||||||
cfg.set('main', 'enabled', 0)
|
cfg.set('main', 'enabled', 0)
|
||||||
fd = open(plugin_conf, 'w+')
|
|
||||||
|
fd = open(tmpfile, 'w+')
|
||||||
cfg.write(fd)
|
cfg.write(fd)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
self.module.atomic_move(tmpfile, plugin_conf)
|
||||||
|
|
||||||
def subscribe(self, **kwargs):
|
def subscribe(self, **kwargs):
|
||||||
raise NotImplementedError("Must be implemented by a sub-class")
|
raise NotImplementedError("Must be implemented by a sub-class")
|
||||||
|
@ -190,6 +198,8 @@ class Rhsm(RegistrationBase):
|
||||||
'''
|
'''
|
||||||
args = ['subscription-manager', 'unregister']
|
args = ['subscription-manager', 'unregister']
|
||||||
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
||||||
|
self.update_plugin_conf('rhnplugin', False)
|
||||||
|
self.update_plugin_conf('subscription-manager', False)
|
||||||
|
|
||||||
def subscribe(self, regexp):
|
def subscribe(self, regexp):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -15,9 +15,11 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {
|
||||||
|
'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
|
@ -196,8 +198,20 @@ EXAMPLES = '''
|
||||||
autosubscribe: yes
|
autosubscribe: yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
subscribed_pool_ids:
|
||||||
|
description: List of pool IDs to which system is now subscribed
|
||||||
|
returned: success
|
||||||
|
type: complex
|
||||||
|
contains: {
|
||||||
|
"8a85f9815ab905d3015ab928c7005de4": "1"
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
import types
|
import types
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -234,16 +248,22 @@ class RegistrationBase(object):
|
||||||
|
|
||||||
def update_plugin_conf(self, plugin, enabled=True):
|
def update_plugin_conf(self, plugin, enabled=True):
|
||||||
plugin_conf = '/etc/yum/pluginconf.d/%s.conf' % plugin
|
plugin_conf = '/etc/yum/pluginconf.d/%s.conf' % plugin
|
||||||
|
|
||||||
if os.path.isfile(plugin_conf):
|
if os.path.isfile(plugin_conf):
|
||||||
|
tmpfd, tmpfile = tempfile.mkstemp()
|
||||||
|
shutil.copy2(plugin_conf, tmpfile)
|
||||||
cfg = configparser.ConfigParser()
|
cfg = configparser.ConfigParser()
|
||||||
cfg.read([plugin_conf])
|
cfg.read([tmpfile])
|
||||||
|
|
||||||
if enabled:
|
if enabled:
|
||||||
cfg.set('main', 'enabled', 1)
|
cfg.set('main', 'enabled', 1)
|
||||||
else:
|
else:
|
||||||
cfg.set('main', 'enabled', 0)
|
cfg.set('main', 'enabled', 0)
|
||||||
fd = open(plugin_conf, 'rwa+')
|
|
||||||
|
fd = open(tmpfile, 'w+')
|
||||||
cfg.write(fd)
|
cfg.write(fd)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
self.module.atomic_move(tmpfile, plugin_conf)
|
||||||
|
|
||||||
def subscribe(self, **kwargs):
|
def subscribe(self, **kwargs):
|
||||||
raise NotImplementedError("Must be implemented by a sub-class")
|
raise NotImplementedError("Must be implemented by a sub-class")
|
||||||
|
@ -392,6 +412,8 @@ class Rhsm(RegistrationBase):
|
||||||
'''
|
'''
|
||||||
args = [SUBMAN_CMD, 'unregister']
|
args = [SUBMAN_CMD, 'unregister']
|
||||||
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
rc, stderr, stdout = self.module.run_command(args, check_rc=True)
|
||||||
|
self.update_plugin_conf('rhnplugin', False)
|
||||||
|
self.update_plugin_conf('subscription-manager', False)
|
||||||
|
|
||||||
def subscribe(self, regexp):
|
def subscribe(self, regexp):
|
||||||
'''
|
'''
|
||||||
|
@ -538,6 +560,7 @@ class RhsmPools(object):
|
||||||
"""
|
"""
|
||||||
This class is used for manipulating pools subscriptions with RHSM
|
This class is used for manipulating pools subscriptions with RHSM
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, module, consumed=False):
|
def __init__(self, module, consumed=False):
|
||||||
self.module = module
|
self.module = module
|
||||||
self.products = self._load_product_list(consumed)
|
self.products = self._load_product_list(consumed)
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {
|
||||||
|
'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'core'}
|
'supported_by': 'community'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
|
@ -133,10 +135,14 @@ EXAMPLES = '''
|
||||||
channels: rhel-x86_64-server-6-foo-1,rhel-x86_64-server-6-bar-1
|
channels: rhel-x86_64-server-6-foo-1,rhel-x86_64-server-6-bar-1
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
RETURN = '''
|
||||||
|
# Default return values
|
||||||
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import xmlrpclib
|
|
||||||
import urlparse
|
import urlparse
|
||||||
|
import xmlrpclib
|
||||||
|
|
||||||
# Attempt to import rhn client tools
|
# Attempt to import rhn client tools
|
||||||
sys.path.insert(0, '/usr/share/rhn')
|
sys.path.insert(0, '/usr/share/rhn')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue