2020-01-17 18:21:42 +03:00
#!/usr/bin/python
# coding: utf-8 -*-
2020-01-24 19:30:16 +03:00
# (c) 2019, John Westcott IV <john.westcott.iv@redhat.com>
2020-01-17 18:21:42 +03:00
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import , division , print_function
__metaclass__ = type
ANSIBLE_METADATA = { ' metadata_version ' : ' 1.1 ' ,
' status ' : [ ' preview ' ] ,
' supported_by ' : ' community ' }
DOCUMENTATION = '''
- - -
2020-01-21 22:44:19 +03:00
module : tower_license
2020-01-17 18:21:42 +03:00
author : " John Westcott IV (@john-westcott-iv) "
version_added : " 2.9 "
short_description : Set the license for Ansible Tower
description :
- Get or Set Ansible Tower license . See
U ( https : / / www . ansible . com / tower ) for an overview .
options :
data :
description :
- The contents of the license file
required : True
2020-01-21 22:44:19 +03:00
type : dict
2020-02-24 23:23:49 +03:00
version_added : " 3.7 "
2020-01-21 22:44:19 +03:00
eula_accepted :
description :
- Whether or not the EULA is accepted .
required : True
type : bool
2020-02-24 23:23:49 +03:00
version_added : " 3.7 "
2020-01-21 22:44:19 +03:00
tower_oauthtoken :
description :
- The Tower OAuth token to use .
required : False
type : str
2020-02-24 23:23:49 +03:00
version_added : " 3.7 "
2020-01-17 18:21:42 +03:00
extends_documentation_fragment : awx . awx . auth
'''
RETURN = ''' # '''
EXAMPLES = '''
- name : Set the license using a file
license :
data : " {{ lookup( ' file ' , ' /tmp/my_tower.license ' ) }} "
2020-01-21 22:44:19 +03:00
eula_accepted : True
2020-01-17 18:21:42 +03:00
'''
from . . module_utils . tower_api import TowerModule
def main ( ) :
module = TowerModule (
argument_spec = dict (
data = dict ( type = ' dict ' , required = True ) ,
eula_accepted = dict ( type = ' bool ' , required = True ) ,
) ,
supports_check_mode = True
)
json_output = { ' changed ' : False }
if not module . params . get ( ' eula_accepted ' ) :
2020-01-24 19:30:16 +03:00
module . fail_json ( msg = ' You must accept the EULA by passing in the param eula_accepted as True ' )
2020-01-17 18:21:42 +03:00
json_output [ ' old_license ' ] = module . get_endpoint ( ' settings/system/ ' ) [ ' json ' ] [ ' LICENSE ' ]
new_license = module . params . get ( ' data ' )
if json_output [ ' old_license ' ] != new_license :
json_output [ ' changed ' ] = True
2020-01-17 23:44:25 +03:00
# Deal with check mode
2020-01-17 18:21:42 +03:00
if module . check_mode :
module . exit_json ( * * json_output )
2020-01-17 23:44:25 +03:00
2020-01-17 18:21:42 +03:00
# We need to add in the EULA
new_license [ ' eula_accepted ' ] = True
module . post_endpoint ( ' config ' , data = new_license )
module . exit_json ( * * json_output )
if __name__ == ' __main__ ' :
main ( )