@ -15,9 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
ANSIBLE_METADATA = { ' metadata_version ' : ' 1.0 ' ,
' status ' : [ ' preview ' ] ,
' supported_by ' : ' community ' }
ANSIBLE_METADATA = {
' metadata_version ' : ' 1.0 ' ,
' status ' : [ ' preview ' ] ,
' supported_by ' : ' community '
}
DOCUMENTATION = '''
@ -196,8 +198,20 @@ EXAMPLES = '''
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 re
import shutil
import tempfile
import types
from ansible . module_utils . basic import AnsibleModule
@ -234,16 +248,22 @@ class RegistrationBase(object):
def update_plugin_conf ( self , plugin , enabled = True ) :
plugin_conf = ' /etc/yum/pluginconf.d/ %s .conf ' % plugin
if os . path . isfile ( plugin_conf ) :
tmpfd , tmpfile = tempfile . mkstemp ( )
shutil . copy2 ( plugin_conf , tmpfile )
cfg = configparser . ConfigParser ( )
cfg . read ( [ plugin_conf ] )
cfg . read ( [ tmpfile ] )
if enabled :
cfg . set ( ' main ' , ' enabled ' , 1 )
else :
cfg . set ( ' main ' , ' enabled ' , 0 )
fd = open ( plugin_conf , ' rwa+ ' )
fd = open ( tmpfile , ' w+ ' )
cfg . write ( fd )
fd . close ( )
self . module . atomic_move ( tmpfile , plugin_conf )
def subscribe ( self , * * kwargs ) :
raise NotImplementedError ( " Must be implemented by a sub-class " )
@ -392,6 +412,8 @@ class Rhsm(RegistrationBase):
'''
args = [ SUBMAN_CMD , ' unregister ' ]
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 ) :
'''
@ -538,6 +560,7 @@ class RhsmPools(object):
"""
This class is used for manipulating pools subscriptions with RHSM
"""
def __init__ ( self , module , consumed = False ) :
self . module = module
self . products = self . _load_product_list ( consumed )