mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 09:57:35 -02:30
update the tower_license module to properly upload manifests
This commit is contained in:
@@ -39,10 +39,11 @@ RETURN = ''' # '''
|
|||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: Set the license using a file
|
- name: Set the license using a file
|
||||||
license:
|
license:
|
||||||
data: "{{ lookup('file', '/tmp/my_tower.license') }}"
|
manifest: "/tmp/my_tower.license"
|
||||||
eula_accepted: True
|
eula_accepted: True
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import base64
|
||||||
from ..module_utils.tower_api import TowerAPIModule
|
from ..module_utils.tower_api import TowerAPIModule
|
||||||
|
|
||||||
|
|
||||||
@@ -50,29 +51,31 @@ def main():
|
|||||||
|
|
||||||
module = TowerAPIModule(
|
module = TowerAPIModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
data=dict(type='dict', required=True),
|
manifest=dict(type='str', required=True),
|
||||||
eula_accepted=dict(type='bool', required=True),
|
eula_accepted=dict(type='bool', required=True),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
json_output = {'changed': False}
|
json_output = {'changed': True}
|
||||||
|
|
||||||
if not module.params.get('eula_accepted'):
|
if not module.params.get('eula_accepted'):
|
||||||
module.fail_json(msg='You must accept the EULA by passing in the param eula_accepted as True')
|
module.fail_json(msg='You must accept the EULA by passing in the param eula_accepted as True')
|
||||||
|
|
||||||
json_output['old_license'] = module.get_endpoint('settings/system/')['json']['LICENSE']
|
try:
|
||||||
new_license = module.params.get('data')
|
manifest = base64.b64encode(
|
||||||
|
open(module.params.get('manifest'), 'rb').read()
|
||||||
|
)
|
||||||
|
except OSError as e:
|
||||||
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
if json_output['old_license'] != new_license:
|
# Deal with check mode
|
||||||
json_output['changed'] = True
|
if module.check_mode:
|
||||||
|
module.exit_json(**json_output)
|
||||||
|
|
||||||
# Deal with check mode
|
module.post_endpoint('config', data={
|
||||||
if module.check_mode:
|
'eula_accepted': True,
|
||||||
module.exit_json(**json_output)
|
'manifest': manifest.decode()
|
||||||
|
})
|
||||||
# We need to add in the EULA
|
|
||||||
new_license['eula_accepted'] = True
|
|
||||||
module.post_endpoint('config', data=new_license)
|
|
||||||
|
|
||||||
module.exit_json(**json_output)
|
module.exit_json(**json_output)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user