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 AlanCoding
parent 9b228d7d2d
commit 64014faf02
17 changed files with 89 additions and 162 deletions
@@ -71,7 +71,7 @@ EXAMPLES = '''
tower_config_file: "~/tower_cli.cfg"
'''
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
@@ -83,8 +83,7 @@ except ImportError:
def main():
argument_spec = tower_argument_spec()
argument_spec.update(dict(
argument_spec = dict(
username=dict(required=True),
first_name=dict(),
last_name=dict(),
@@ -93,12 +92,9 @@ def main():
superuser=dict(type='bool', default=False),
auditor=dict(type='bool', default=False),
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)
username = module.params.get('username')
first_name = module.params.get('first_name')
@@ -130,6 +126,5 @@ def main():
module.exit_json(**json_output)
from ansible.module_utils.basic import AnsibleModule
if __name__ == '__main__':
main()