mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 11:00:03 -03:30
Fixing config loading issues when the config has no [general] section
Fixed typo in help documentation Fix up sanity errors and update converted modules Remove unnecessary test playbook file
This commit is contained in:
parent
4fc2c58ae7
commit
018dd4c1c3
@ -7,7 +7,7 @@ from ansible.module_utils.six import PY2
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse, urlencode
|
||||
from ansible.module_utils.six.moves.urllib.error import HTTPError
|
||||
from ansible.module_utils.six.moves.http_cookiejar import CookieJar
|
||||
from ansible.module_utils.six.moves.configparser import ConfigParser, NoOptionError
|
||||
from ansible.module_utils.six.moves.configparser import ConfigParser, NoOptionError, MissingSectionHeaderError
|
||||
from socket import gethostbyname
|
||||
import re
|
||||
from json import loads, dumps
|
||||
@ -137,8 +137,10 @@ class TowerModule(AnsibleModule):
|
||||
if not access(config_path, R_OK):
|
||||
raise ConfigFileException("The specified config file can not be read")
|
||||
|
||||
config.read(config_path)
|
||||
if not config.has_section('general'):
|
||||
# If the config has not sections we will get a MissingSectionHeaderError
|
||||
try:
|
||||
config.read(config_path)
|
||||
except MissingSectionHeaderError:
|
||||
self.warn("No general section in file, auto-appending")
|
||||
with open(config_path, 'r') as f:
|
||||
config.read_string('[general]\n%s' % f.read())
|
||||
|
||||
@ -33,6 +33,11 @@ options:
|
||||
- Fail loudly if the I(job_id) can not be canceled
|
||||
default: False
|
||||
type: bool
|
||||
tower_oauthtoken:
|
||||
description:
|
||||
- The Tower OAuth token to use.
|
||||
required: False
|
||||
type: str
|
||||
extends_documentation_fragment: awx.awx.auth
|
||||
'''
|
||||
|
||||
@ -53,6 +58,7 @@ id:
|
||||
|
||||
from ..module_utils.tower_api import TowerModule
|
||||
|
||||
|
||||
def main():
|
||||
# Any additional arguments that are not fields of the item can be added here
|
||||
argument_spec = dict(
|
||||
@ -77,25 +83,25 @@ def main():
|
||||
}
|
||||
})
|
||||
|
||||
if job == None:
|
||||
if job is None:
|
||||
module.fail_json(msg="Unable to find job with id {0}".format(job_id))
|
||||
|
||||
cancel_page = module.get_endpoint(job['related']['cancel'])
|
||||
if 'json' not in cancel_page or 'can_cancel' not in cancel_page['json']:
|
||||
module.fail_json(msg="Failed to cancel job, got unexpected response from tower", **{ 'response': cancel_page })
|
||||
module.fail_json(msg="Failed to cancel job, got unexpected response from tower", **{'response': cancel_page})
|
||||
|
||||
if not cancel_page['json']['can_cancel']:
|
||||
if fail_if_not_running:
|
||||
module.fail_json(msg="Job is not running")
|
||||
else:
|
||||
module.exit_json(**{ 'changed': False })
|
||||
module.exit_json(**{'changed': False})
|
||||
|
||||
response = module.post_endpoint(job['related']['cancel'], **{ 'data': {} })
|
||||
results = module.post_endpoint(job['related']['cancel'], **{'data': {}})
|
||||
|
||||
if response['status_code'] != 202:
|
||||
module.fail_json(msg="Failed to cancel job, see response for details", **{'response': results })
|
||||
if results['status_code'] != 202:
|
||||
module.fail_json(msg="Failed to cancel job, see response for details", **{'response': results})
|
||||
|
||||
module.exit_json(**{ 'changed': True })
|
||||
module.exit_json(**{'changed': True})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -60,16 +60,16 @@ options:
|
||||
scm_branch:
|
||||
description:
|
||||
- A specific of the SCM project to run the template on.
|
||||
- This is only applicable if your project allows for branch override
|
||||
- This is only applicable if your project allows for branch override.
|
||||
type: str
|
||||
skip_tags:
|
||||
decription:
|
||||
description:
|
||||
- Specific tags to skip from the playbook.
|
||||
type: list
|
||||
verbosity:
|
||||
description:
|
||||
- Verbosity level for this job run
|
||||
tpye: int
|
||||
type: int
|
||||
choices: [ 0, 1, 2, 3, 4, 5 ]
|
||||
diff_mode:
|
||||
description:
|
||||
@ -78,6 +78,12 @@ options:
|
||||
credential_passwords:
|
||||
description:
|
||||
- Passwords for credentials which are set to prompt on launch
|
||||
type: dict
|
||||
tower_oauthtoken:
|
||||
description:
|
||||
- The Tower OAuth token to use.
|
||||
required: False
|
||||
type: str
|
||||
extends_documentation_fragment: awx.awx.auth
|
||||
'''
|
||||
|
||||
@ -130,22 +136,23 @@ status:
|
||||
|
||||
from ..module_utils.tower_api import TowerModule
|
||||
|
||||
|
||||
def main():
|
||||
# Any additional arguments that are not fields of the item can be added here
|
||||
argument_spec = dict(
|
||||
name=dict(type=str, required=True, aliases=['job_template']),
|
||||
job_type=dict(type=str, choices=['run', 'check']),
|
||||
inventory=dict(type=str, default=None),
|
||||
name=dict(type='str', required=True, aliases=['job_template']),
|
||||
job_type=dict(type='str', choices=['run', 'check']),
|
||||
inventory=dict(type='str', default=None),
|
||||
# Credentials will be a str instead of a list for backwards compatability
|
||||
credentials=dict(type='list', default=None, aliases=['credential']),
|
||||
limit=dict(),
|
||||
tags=dict(type='list'),
|
||||
extra_vars=dict(type=dict, required=False),
|
||||
scm_branch=dict(type=str, required=False),
|
||||
skip_tags=dict(type=list, required=False),
|
||||
verbosity=dict(type=int, required=False, choices=[0,1,2,3,4,5]),
|
||||
diff_mode=dict(type=bool, required=False),
|
||||
credential_passwords=dict(type=dict, required=False),
|
||||
extra_vars=dict(type='dict', required=False),
|
||||
scm_branch=dict(type='str', required=False),
|
||||
skip_tags=dict(type='list', required=False),
|
||||
verbosity=dict(type='int', required=False, choices=[0, 1, 2, 3, 4, 5]),
|
||||
diff_mode=dict(type='bool', required=False),
|
||||
credential_passwords=dict(type='dict', required=False),
|
||||
)
|
||||
|
||||
# Create a module for ourselves
|
||||
@ -179,7 +186,7 @@ def main():
|
||||
if credentials:
|
||||
post_data['credentials'] = []
|
||||
for credential in credentials:
|
||||
post_data['credentials'].append( module.resolve_name_to_id('credentials', credential) )
|
||||
post_data['credentials'].append(module.resolve_name_to_id('credentials', credential))
|
||||
|
||||
# Attempt to look up job_template based on the provided name
|
||||
job_template = module.get_one('job_templates', **{
|
||||
@ -188,7 +195,7 @@ def main():
|
||||
}
|
||||
})
|
||||
|
||||
if job_template == None:
|
||||
if job_template is None:
|
||||
module.fail_json(msg="Unable to find job template by name {0}".format(name))
|
||||
|
||||
# The API will allow you to submit values to a jb launch that are not prompt on launch.
|
||||
@ -211,13 +218,13 @@ def main():
|
||||
if module.params.get(variable_name) and not job_template[check_vars_to_prompts[variable_name]]:
|
||||
param_errors.append("The field {0} was specified but the job template does not allow for it to be overridden".format(variable_name))
|
||||
if len(param_errors) > 0:
|
||||
module.fail_json(msg="Parameters specified which can not be passed into job template, see errors for details", **{ 'errors': param_errors })
|
||||
module.fail_json(msg="Parameters specified which can not be passed into job template, see errors for details", **{'errors': param_errors})
|
||||
|
||||
# Launch the job
|
||||
results = module.post_endpoint(job_template['related']['launch'], **{ 'data': post_data })
|
||||
|
||||
results = module.post_endpoint(job_template['related']['launch'], **{'data': post_data})
|
||||
|
||||
if results['status_code'] != 201:
|
||||
module.fail_json(msg="Failed to launch job, see response for details", **{'response': results })
|
||||
module.fail_json(msg="Failed to launch job, see response for details", **{'response': results})
|
||||
|
||||
module.exit_json(**{
|
||||
'changed': True,
|
||||
@ -225,5 +232,6 @@ def main():
|
||||
'status': results['json']['status'],
|
||||
})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@ -101,11 +101,6 @@ def main():
|
||||
# instance_group_names = module.params.get('instance_groups')
|
||||
state = module.params.get('state')
|
||||
|
||||
# Attempt to look up the related items the user specified (these will fail the module if not found)
|
||||
# instance_group_objects = []
|
||||
# for instance_name in instance_group_names:
|
||||
# instance_group_objects.append(module.resolve_name_to_id('instance_groups', instance_name))
|
||||
|
||||
# Attempt to look up organization based on the provided name
|
||||
organization = module.get_one('organizations', **{
|
||||
'data': {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user