mirror of
https://github.com/ansible/awx.git
synced 2026-03-24 20:35:02 -02:30
Make non-required params actually optional, fix idempotency issues
This commit is contained in:
@@ -115,9 +115,9 @@ def main():
|
|||||||
'name': new_name if new_name else name,
|
'name': new_name if new_name else name,
|
||||||
'inventory': inventory_id,
|
'inventory': inventory_id,
|
||||||
}
|
}
|
||||||
if description:
|
if description is not None:
|
||||||
group_fields['description'] = description
|
group_fields['description'] = description
|
||||||
if variables:
|
if variables is not None:
|
||||||
group_fields['variables'] = json.dumps(variables)
|
group_fields['variables'] = json.dumps(variables)
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
|
|||||||
@@ -123,11 +123,12 @@ def main():
|
|||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
host_fields = {
|
host_fields = {
|
||||||
'name': new_name if new_name else name,
|
'name': new_name if new_name else name,
|
||||||
'description': description,
|
|
||||||
'inventory': inventory_id,
|
'inventory': inventory_id,
|
||||||
'enabled': enabled,
|
'enabled': enabled,
|
||||||
}
|
}
|
||||||
if variables:
|
if description is not None:
|
||||||
|
host_fields['description'] = description
|
||||||
|
if variables is not None:
|
||||||
host_fields['variables'] = json.dumps(variables)
|
host_fields['variables'] = json.dumps(variables)
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
|
|
||||||
from ..module_utils.tower_api import TowerModule
|
from ..module_utils.tower_api import TowerModule
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -122,12 +123,14 @@ def main():
|
|||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
inventory_fields = {
|
inventory_fields = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'description': description,
|
|
||||||
'organization': org_id,
|
'organization': org_id,
|
||||||
'variables': variables,
|
|
||||||
'kind': kind,
|
'kind': kind,
|
||||||
'host_filter': host_filter,
|
'host_filter': host_filter,
|
||||||
}
|
}
|
||||||
|
if description is not None:
|
||||||
|
inventory_fields['description'] = description
|
||||||
|
if variables is not None:
|
||||||
|
inventory_fields['variables'] = json.dumps(variables)
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -209,11 +209,11 @@ def main():
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||||
if credential:
|
if credential is not None:
|
||||||
inventory_source_fields['credential'] = module.resolve_name_to_id('credentials', credential)
|
inventory_source_fields['credential'] = module.resolve_name_to_id('credentials', credential)
|
||||||
if source_project:
|
if source_project is not None:
|
||||||
inventory_source_fields['source_project'] = module.resolve_name_to_id('projects', source_project)
|
inventory_source_fields['source_project'] = module.resolve_name_to_id('projects', source_project)
|
||||||
if source_script:
|
if source_script is not None:
|
||||||
inventory_source_fields['source_script'] = module.resolve_name_to_id('inventory_scripts', source_script)
|
inventory_source_fields['source_script'] = module.resolve_name_to_id('inventory_scripts', source_script)
|
||||||
|
|
||||||
OPTIONAL_VARS = (
|
OPTIONAL_VARS = (
|
||||||
|
|||||||
@@ -112,11 +112,11 @@ def main():
|
|||||||
|
|
||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
org_fields = {'name': name}
|
org_fields = {'name': name}
|
||||||
if description:
|
if description is not None:
|
||||||
org_fields['description'] = description
|
org_fields['description'] = description
|
||||||
if custom_virtualenv:
|
if custom_virtualenv is not None:
|
||||||
org_fields['custom_virtualenv'] = custom_virtualenv
|
org_fields['custom_virtualenv'] = custom_virtualenv
|
||||||
if max_hosts:
|
if max_hosts is not None:
|
||||||
org_fields['max_hosts'] = max_hosts
|
org_fields['max_hosts'] = max_hosts
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ def main():
|
|||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
project_fields = {
|
project_fields = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'description': description,
|
|
||||||
'scm_type': scm_type,
|
'scm_type': scm_type,
|
||||||
'scm_url': scm_url,
|
'scm_url': scm_url,
|
||||||
'scm_branch': scm_branch,
|
'scm_branch': scm_branch,
|
||||||
@@ -251,6 +250,8 @@ def main():
|
|||||||
'scm_update_cache_timeout': scm_update_cache_timeout,
|
'scm_update_cache_timeout': scm_update_cache_timeout,
|
||||||
'custom_virtualenv': custom_virtualenv,
|
'custom_virtualenv': custom_virtualenv,
|
||||||
}
|
}
|
||||||
|
if description is not None:
|
||||||
|
project_fields['description'] = description
|
||||||
if scm_credential is not None:
|
if scm_credential is not None:
|
||||||
project_fields['credential'] = scm_credential_id
|
project_fields['credential'] = scm_credential_id
|
||||||
if scm_allow_override is not None:
|
if scm_allow_override is not None:
|
||||||
|
|||||||
@@ -107,9 +107,10 @@ def main():
|
|||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
team_fields = {
|
team_fields = {
|
||||||
'name': new_name if new_name else name,
|
'name': new_name if new_name else name,
|
||||||
'description': description,
|
|
||||||
'organization': org_id
|
'organization': org_id
|
||||||
}
|
}
|
||||||
|
if description is not None:
|
||||||
|
team_fields['description'] = description
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ def main():
|
|||||||
first_name=dict(),
|
first_name=dict(),
|
||||||
last_name=dict(),
|
last_name=dict(),
|
||||||
password=dict(no_log=True),
|
password=dict(no_log=True),
|
||||||
email=dict(required=False),
|
email=dict(required=False, default=''),
|
||||||
superuser=dict(type='bool', default=False),
|
superuser=dict(type='bool', default=False),
|
||||||
auditor=dict(type='bool', default=False),
|
auditor=dict(type='bool', default=False),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
@@ -129,6 +129,7 @@ def main():
|
|||||||
|
|
||||||
# Extract our parameters
|
# Extract our parameters
|
||||||
state = module.params.get('state')
|
state = module.params.get('state')
|
||||||
|
email = module.params.get('email')
|
||||||
|
|
||||||
# Create the data that gets sent for create and update
|
# Create the data that gets sent for create and update
|
||||||
user_fields = {
|
user_fields = {
|
||||||
@@ -136,10 +137,11 @@ def main():
|
|||||||
'first_name': module.params.get('first_name'),
|
'first_name': module.params.get('first_name'),
|
||||||
'last_name': module.params.get('last_name'),
|
'last_name': module.params.get('last_name'),
|
||||||
'password': module.params.get('password'),
|
'password': module.params.get('password'),
|
||||||
'email': module.params.get('email'),
|
|
||||||
'superuser': module.params.get('superuser'),
|
'superuser': module.params.get('superuser'),
|
||||||
'auditor': module.params.get('auditor'),
|
'auditor': module.params.get('auditor'),
|
||||||
}
|
}
|
||||||
|
if email is not None:
|
||||||
|
user_fields['email'] = email
|
||||||
|
|
||||||
# Attempt to look up user based on the provided username
|
# Attempt to look up user based on the provided username
|
||||||
user = module.get_one('users', **{
|
user = module.get_one('users', **{
|
||||||
|
|||||||
Reference in New Issue
Block a user