mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
tower cred: implement credential /api/v1/ kind compatability
This commit is contained in:
parent
640749d54f
commit
9cb4b70e27
1 changed files with 44 additions and 22 deletions
|
@ -165,9 +165,41 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _add_input_(module, param, results):
|
KIND_CHOICES = {
|
||||||
if module.params.get(param):
|
'ssh': 'Machine',
|
||||||
results[param] = module.params.get(param)
|
'vault': 'Ansible Vault',
|
||||||
|
'net': 'Network',
|
||||||
|
'scm': 'Source Control',
|
||||||
|
'aws': 'Amazon Web Services',
|
||||||
|
'vmware': 'VMware vCenter',
|
||||||
|
'satellite6': 'Red Hat Satellite 6',
|
||||||
|
'cloudforms': 'Red Hat CloudForms',
|
||||||
|
'gce': 'Google Compute Engine',
|
||||||
|
'azure_rm': 'Microsoft Azure Resource Manager',
|
||||||
|
'openstack': 'OpenStack',
|
||||||
|
'rhv': 'Red Hat Virtualization',
|
||||||
|
'insights': 'Insights',
|
||||||
|
'tower': 'Ansible Tower',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def credential_type_for_v1_kind(params, module):
|
||||||
|
credential_type_res = tower_cli.get_resource('credential_type')
|
||||||
|
kind = params.pop('kind')
|
||||||
|
arguments = {'managed_by_tower': True}
|
||||||
|
if kind == 'ssh':
|
||||||
|
if params.get('vault_password'):
|
||||||
|
arguments['kind'] = 'vault'
|
||||||
|
else:
|
||||||
|
arguments['kind'] = 'ssh'
|
||||||
|
elif kind in ('net', 'scm', 'insights', 'vault'):
|
||||||
|
arguments['kind'] = kind
|
||||||
|
elif kind in KIND_CHOICES:
|
||||||
|
arguments.update(dict(
|
||||||
|
kind='cloud',
|
||||||
|
name=KIND_CHOICES[kind]
|
||||||
|
))
|
||||||
|
return credential_type_res.get(**arguments)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -178,8 +210,7 @@ def main():
|
||||||
user=dict(),
|
user=dict(),
|
||||||
team=dict(),
|
team=dict(),
|
||||||
kind=dict(required=True,
|
kind=dict(required=True,
|
||||||
choices=["ssh", "net", "scm", "aws", "rax", "vmware", "satellite6",
|
choices=KIND_CHOICES.keys()),
|
||||||
"cloudforms", "gce", "azure", "azure_rm", "openstack"]),
|
|
||||||
host=dict(),
|
host=dict(),
|
||||||
username=dict(),
|
username=dict(),
|
||||||
password=dict(no_log=True),
|
password=dict(no_log=True),
|
||||||
|
@ -227,8 +258,7 @@ def main():
|
||||||
org = org_res.get(name=organization)
|
org = org_res.get(name=organization)
|
||||||
params['organization'] = org['id']
|
params['organization'] = org['id']
|
||||||
|
|
||||||
credential_type_res = tower_cli.get_resource('credential_type')
|
credential_type = credential_type_for_v1_kind(module.params, module)
|
||||||
credential_type = credential_type_res.get(kind=module.params.get('kind'))
|
|
||||||
params['credential_type'] = credential_type['id']
|
params['credential_type'] = credential_type['id']
|
||||||
|
|
||||||
if module.params.get('description'):
|
if module.params.get('description'):
|
||||||
|
@ -254,21 +284,13 @@ def main():
|
||||||
with open(filename, 'rb') as f:
|
with open(filename, 'rb') as f:
|
||||||
params['inputs']['ssh_key_data'] = f.read()
|
params['inputs']['ssh_key_data'] = f.read()
|
||||||
|
|
||||||
_add_input_(module, 'authorize', params['inputs'])
|
for key in ('authorize', 'authorize_password', 'client', 'secret',
|
||||||
_add_input_(module, 'authorize_password', params['inputs'])
|
'tenant', 'subscription', 'domain', 'become_method',
|
||||||
_add_input_(module, 'client', params['inputs'])
|
'become_username', 'become_password', 'vault_password',
|
||||||
_add_input_(module, 'secret', params['inputs'])
|
'project', 'host', 'username', 'password',
|
||||||
_add_input_(module, 'tenant', params['inputs'])
|
'ssh_key_unlock'):
|
||||||
_add_input_(module, 'subscription', params['inputs'])
|
if module.params.get(key):
|
||||||
_add_input_(module, 'domain', params['inputs'])
|
params['inputs'][key] = module.params.get(key)
|
||||||
_add_input_(module, 'become_method', params['inputs'])
|
|
||||||
_add_input_(module, 'become_username', params['inputs'])
|
|
||||||
_add_input_(module, 'become_password', params['inputs'])
|
|
||||||
_add_input_(module, 'vault_password', params['inputs'])
|
|
||||||
_add_input_(module, 'project', params['inputs'])
|
|
||||||
_add_input_(module, 'host', params['inputs'])
|
|
||||||
_add_input_(module, 'username', params['inputs'])
|
|
||||||
_add_input_(module, 'password', params['inputs'])
|
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
result = credential.modify(**params)
|
result = credential.modify(**params)
|
||||||
|
|
Loading…
Reference in a new issue