2017-02-20 23:16:32 +03:00
#!/usr/bin/python
2017-05-11 19:26:36 +03:00
# coding: utf-8 -*-
2017-02-20 23:16:32 +03:00
# (c) 2017, Wayne Witzel III <wayne@riotousliving.com>
Remove wildcard imports
Made the following changes:
* Removed wildcard imports
* Replaced long form of GPL header with short form
* Removed get_exception usage
* Added from __future__ boilerplate
* Adjust division operator to // where necessary
For the following files:
* web_infrastructure modules
* system modules
* linode, lxc, lxd, atomic, cloudscale, dimensiondata, ovh, packet,
profitbricks, pubnub, smartos, softlayer, univention modules
* compat dirs (disabled as its used intentionally)
2017-07-28 08:55:24 +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
2017-02-20 23:16:32 +03:00
2017-08-16 06:16:38 +03:00
ANSIBLE_METADATA = { ' metadata_version ' : ' 1.1 ' ,
2017-03-14 19:07:22 +03:00
' status ' : [ ' preview ' ] ,
' supported_by ' : ' community ' }
2017-02-20 23:16:32 +03:00
DOCUMENTATION = '''
- - -
module : tower_team
2017-03-09 19:20:25 +03:00
author : " Wayne Witzel III (@wwitzel3) "
2017-02-20 23:16:32 +03:00
version_added : " 2.3 "
short_description : create , update , or destroy Ansible Tower team .
description :
- Create , update , or destroy Ansible Tower teams . See
U ( https : / / www . ansible . com / tower ) for an overview .
options :
name :
description :
- Name to use for the team .
required : True
2019-09-30 23:01:44 +03:00
type : str
2020-01-21 22:44:19 +03:00
new_name :
description :
- To use when changing a team ' s name.
2020-02-20 20:43:22 +03:00
required : False
2020-01-21 22:44:19 +03:00
type : str
2020-02-24 23:23:49 +03:00
version_added : " 3.7 "
2019-09-30 23:01:44 +03:00
description :
description :
- The description to use for the team .
2020-02-24 23:23:49 +03:00
required : False
2019-09-30 23:01:44 +03:00
type : str
2017-02-20 23:16:32 +03:00
organization :
description :
- Organization the team should be made a member of .
required : True
2019-09-30 23:01:44 +03:00
type : str
2017-02-20 23:16:32 +03:00
state :
description :
- Desired state of the resource .
choices : [ " present " , " absent " ]
2018-03-16 00:15:24 +03:00
default : " present "
2019-09-30 23:01:44 +03:00
type : str
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 "
2019-09-18 15:43:36 +03:00
extends_documentation_fragment : awx . awx . auth
2017-02-20 23:16:32 +03:00
'''
EXAMPLES = '''
- name : Create tower team
tower_team :
name : Team Name
description : Team Description
organization : test - org
state : present
tower_config_file : " ~/tower_cli.cfg "
'''
2020-01-17 18:21:42 +03:00
from . . module_utils . tower_api import TowerModule
2017-02-20 23:16:32 +03:00
def main ( ) :
2020-01-17 18:21:42 +03:00
# Any additional arguments that are not fields of the item can be added here
2018-08-02 18:17:39 +03:00
argument_spec = dict (
2017-10-02 23:21:24 +03:00
name = dict ( required = True ) ,
2020-01-17 18:21:42 +03:00
new_name = dict ( required = False ) ,
2020-02-24 23:23:49 +03:00
description = dict ( required = False ) ,
2017-10-02 23:21:24 +03:00
organization = dict ( required = True ) ,
state = dict ( choices = [ ' present ' , ' absent ' ] , default = ' present ' ) ,
2018-08-02 18:17:39 +03:00
)
2017-10-02 23:21:24 +03:00
2020-01-17 18:21:42 +03:00
# Create a module for ourselves
2018-08-02 18:17:39 +03:00
module = TowerModule ( argument_spec = argument_spec , supports_check_mode = True )
2017-02-20 23:16:32 +03:00
2020-01-17 18:21:42 +03:00
# Extract our parameters
2017-02-20 23:16:32 +03:00
name = module . params . get ( ' name ' )
2020-01-17 18:21:42 +03:00
new_name = module . params . get ( ' new_name ' )
2017-02-20 23:16:32 +03:00
description = module . params . get ( ' description ' )
organization = module . params . get ( ' organization ' )
state = module . params . get ( ' state ' )
2020-01-29 21:33:04 +03:00
# Attempt to look up the related items the user specified (these will fail the module if not found)
2020-01-17 18:21:42 +03:00
org_id = module . resolve_name_to_id ( ' organizations ' , organization )
2020-01-29 21:33:04 +03:00
# Attempt to look up team based on the provided name and org ID
2020-01-17 18:21:42 +03:00
team = module . get_one ( ' teams ' , * * {
' data ' : {
' name ' : name ,
' organization ' : org_id
}
} )
2020-02-12 00:32:41 +03:00
# Create the data that gets sent for create and update
2020-01-21 22:44:19 +03:00
team_fields = {
2020-01-24 19:30:16 +03:00
' name ' : new_name if new_name else name ,
2020-01-21 22:44:19 +03:00
' organization ' : org_id
}
2020-02-26 07:51:26 +03:00
if description is not None :
team_fields [ ' description ' ] = description
2020-01-21 22:44:19 +03:00
2020-01-29 00:56:37 +03:00
if state == ' absent ' :
2020-01-29 19:52:09 +03:00
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
2020-01-29 00:56:37 +03:00
module . delete_if_needed ( team )
elif state == ' present ' :
2020-01-29 21:33:04 +03:00
# If the state was present and we can let the module build or update the existing team, this will return on its own
2020-01-29 17:54:35 +03:00
module . create_or_update_if_needed ( team , team_fields , endpoint = ' teams ' , item_type = ' team ' )
2017-02-20 23:16:32 +03:00
if __name__ == ' __main__ ' :
main ( )