Tower modules: move HAS_TOWER_CLI check in module_utils and minor improvements (#39809)

* tower_* modules: move HAS_TOWER_CLI in TowerModule

Besides this change allows to define other common parameters such as
mutually_exclusive.

* tower_*: config file can not be used with auth params

* tower module_utils: remove useless call to expanduser

'path' type: expanduser & expandvars are automatically called
This commit is contained in:
Pilou 2018-08-02 17:17:39 +02:00 committed by Brian Coca
commit 12973e0541
17 changed files with 89 additions and 162 deletions

View file

@ -128,7 +128,7 @@ EXAMPLES = '''
import os
from ansible.module_utils._text import to_text
from ansible.module_utils.ansible_tower import tower_argument_spec, tower_auth_config, tower_check_mode, HAS_TOWER_CLI
from ansible.module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
try:
import tower_cli
@ -178,8 +178,7 @@ def credential_type_for_v1_kind(params, module):
def main():
argument_spec = tower_argument_spec()
argument_spec.update(dict(
argument_spec = dict(
name=dict(required=True),
user=dict(),
team=dict(),
@ -206,12 +205,9 @@ def main():
organization=dict(required=True),
project=dict(),
state=dict(choices=['present', 'absent'], default='present'),
))
)
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
if not HAS_TOWER_CLI:
module.fail_json(msg='ansible-tower-cli required for this module')
module = TowerModule(argument_spec=argument_spec, supports_check_mode=True)
name = module.params.get('name')
organization = module.params.get('organization')
@ -291,6 +287,5 @@ def main():
module.exit_json(**json_output)
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()