Added env variable CONTROLLER_HOST, et al. Add awx.awx namespace to the runtime.yml redirects, and added templating task to change to ansible.controller

This commit is contained in:
Seth Foster 2021-05-06 15:04:52 -04:00
parent 1ade9b3a7d
commit 39b26c8f0e
No known key found for this signature in database
GPG Key ID: 86E90D96F7184028
9 changed files with 75 additions and 67 deletions

View File

@ -39,93 +39,93 @@ plugin_routing:
redirect: awx.awx.schedule_rrule
modules:
tower_job_list:
redirect: job_list
redirect: awx.awx.job_list
tower_job_launch:
redirect: job_launch
redirect: awx.awx.job_launch
tower_workflow_job_template:
redirect: workflow_job_template
redirect: awx.awx.workflow_job_template
tower_team:
redirect: team
redirect: awx.awx.team
tower_job_wait:
redirect: job_wait
redirect: awx.awx.job_wait
tower_application:
redirect: application
redirect: awx.awx.application
tower_ad_hoc_command_wait:
redirect: ad_hoc_command_wait
redirect: awx.awx.ad_hoc_command_wait
tower_credential:
redirect: credential
redirect: awx.awx.credential
tower_label:
redirect: label
redirect: awx.awx.label
tower_group:
redirect: group
redirect: awx.awx.group
tower_host:
redirect: host
redirect: awx.awx.host
tower_schedule:
redirect: schedule
redirect: awx.awx.schedule
tower_role:
redirect: role
redirect: awx.awx.role
tower_ad_hoc_command:
redirect: ad_hoc_command
redirect: awx.awx.ad_hoc_command
tower_execution_environment:
redirect: execution_environment
redirect: awx.awx.execution_environment
tower_inventory_source_update:
redirect: inventory_source_update
redirect: awx.awx.inventory_source_update
tower_instance_group:
redirect: instance_group
redirect: awx.awx.instance_group
tower_settings:
redirect: settings
redirect: awx.awx.settings
tower_meta:
redirect: controller_meta
redirect: awx.awx.controller_meta
tower_export:
redirect: export
redirect: awx.awx.export
tower_ad_hoc_command_cancel:
redirect: ad_hoc_command_cancel
redirect: awx.awx.ad_hoc_command_cancel
tower_inventory_source:
redirect: inventory_source
redirect: awx.awx.inventory_source
tower_user:
redirect: user
redirect: awx.awx.user
tower_workflow_launch:
redirect: workflow_launch
redirect: awx.awx.workflow_launch
tower_project:
redirect: project
redirect: awx.awx.project
tower_token:
redirect: token
redirect: awx.awx.token
tower_credential_type:
redirect: credential_type
redirect: awx.awx.credential_type
tower_license:
redirect: license
redirect: awx.awx.license
tower_project_update:
redirect: project_update
redirect: awx.awx.project_update
tower_notification_template:
redirect: notification_template
redirect: awx.awx.notification_template
tower_organization:
redirect: organization
redirect: awx.awx.organization
tower_job_template:
redirect: job_template
redirect: awx.awx.job_template
tower_workflow_job_template_node:
redirect: workflow_job_template_node
redirect: awx.awx.workflow_job_template_node
tower_job_cancel:
redirect: job_cancel
redirect: awx.awx.job_cancel
tower_import:
redirect: import
redirect: awx.awx.import
tower_credential_input_source:
redirect: credential_input_source
redirect: awx.awx.credential_input_source
tower_inventory:
redirect: inventory
redirect: awx.awx.inventory
tower_receive:
redirect: receive
redirect: awx.awx.receive
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
tower_send:
redirect: send
redirect: awx.awx.send
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
tower_workflow_template:
redirect: workflow_template
redirect: awx.awx.workflow_template
deprecation:
removal_date: TBD
warning_text: see plugin documentation for details
tower_notification:
redirect: notification_template
redirect: awx.awx.notification_template

View File

@ -81,7 +81,7 @@ def handle_error(**kwargs):
class InventoryModule(BaseInventoryPlugin):
NAME = 'awx.awx.controller' # REPLACE
# Stays backward compatible with tower inventory script.
# Stays backward compatible with the inventory script.
# If the user supplies '@tower_inventory' as path, the plugin will read from environment variables.
no_config_file_supplied = False

View File

@ -75,7 +75,7 @@ EXAMPLES = """
- name: Load the UI settings specifying the connection info
set_fact:
controller_settings: "{{ lookup('awx.awx.controller_api', 'settings/ui' host='tower.example.com', username='admin', password=my_pass_var, verify_ssl=False) }}"
controller_settings: "{{ lookup('awx.awx.controller_api', 'settings/ui' host='controller.example.com', username='admin', password=my_pass_var, verify_ssl=False) }}"
- name: Report the usernames of all users with admin privs
debug:

View File

@ -254,26 +254,28 @@ class ControllerAPIModule(ControllerModule):
# In PY2 we get back an HTTPResponse object but PY2 is returning an addinfourl
# First try to get the headers in PY3 format and then drop down to PY2.
try:
tower_type = response.getheader('X-API-Product-Name', None)
tower_version = response.getheader('X-API-Product-Version', None)
controller_type = response.getheader('X-API-Product-Name', None)
controller_version = response.getheader('X-API-Product-Version', None)
except Exception:
tower_type = response.info().getheader('X-API-Product-Name', None)
tower_version = response.info().getheader('X-API-Product-Version', None)
controller_type = response.info().getheader('X-API-Product-Name', None)
controller_version = response.info().getheader('X-API-Product-Version', None)
parsed_collection_version = Version(self._COLLECTION_VERSION).version
parsed_tower_version = Version(tower_version).version
if tower_type == 'AWX':
parsed_controller_version = Version(controller_version).version
if controller_type == 'AWX':
collection_compare_ver = parsed_collection_version[0]
tower_compare_ver = parsed_tower_version[0]
controller_compare_ver = parsed_controller_version[0]
else:
collection_compare_ver = "{0}.{1}".format(parsed_collection_version[0], parsed_collection_version[1])
tower_compare_ver = '{0}.{1}'.format(parsed_tower_version[0], parsed_tower_version[1])
controller_compare_ver = '{0}.{1}'.format(parsed_controller_version[0], parsed_controller_version[1])
if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != tower_type:
self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, tower_type))
elif collection_compare_ver != tower_compare_ver:
if self._COLLECTION_TYPE not in self.collection_to_version or self.collection_to_version[self._COLLECTION_TYPE] != controller_type:
self.warn("You are using the {0} version of this collection but connecting to {1}".format(self._COLLECTION_TYPE, controller_type))
elif collection_compare_ver != controller_compare_ver:
self.warn(
"You are running collection version {0} but connecting to {2} version {1}".format(self._COLLECTION_VERSION, tower_version, tower_type)
"You are running collection version {0} but connecting to {2} version {1}".format(
self._COLLECTION_VERSION, controller_version, controller_type
)
)
self.version_checked = True
@ -694,10 +696,10 @@ class ControllerAPIModule(ControllerModule):
resp = he.read()
except Exception as e:
resp = 'unknown {0}'.format(e)
self.warn('Failed to release tower token: {0}, response: {1}'.format(he, resp))
self.warn('Failed to release token: {0}, response: {1}'.format(he, resp))
except (Exception) as e:
# Sanity check: Did the server send back some kind of internal error?
self.warn('Failed to release tower token {0}: {1}'.format(self.oauth_token_id, e))
self.warn('Failed to release token {0}: {1}'.format(self.oauth_token_id, e))
def is_job_done(self, job_status):
if job_status in ['new', 'pending', 'waiting', 'running']:

View File

@ -32,11 +32,11 @@ class ItemNotDefined(Exception):
class ControllerModule(AnsibleModule):
url = None
AUTH_ARGSPEC = dict(
tower_host=dict(required=False, fallback=(env_fallback, ['TOWER_HOST'])),
tower_username=dict(required=False, fallback=(env_fallback, ['TOWER_USERNAME'])),
tower_password=dict(no_log=True, required=False, fallback=(env_fallback, ['TOWER_PASSWORD'])),
validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['TOWER_VERIFY_SSL'])),
tower_oauthtoken=dict(type='raw', no_log=True, required=False, fallback=(env_fallback, ['TOWER_OAUTH_TOKEN'])),
tower_host=dict(required=False, fallback=(env_fallback, ['CONTROLLER_HOST', 'TOWER_HOST'])),
tower_username=dict(required=False, fallback=(env_fallback, ['CONTROLLER_USERNAME', 'TOWER_USERNAME'])),
tower_password=dict(no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_PASSWORD', 'TOWER_PASSWORD'])),
validate_certs=dict(type='bool', aliases=['tower_verify_ssl'], required=False, fallback=(env_fallback, ['CONTROLLER_VERIFY_SSL', 'TOWER_VERIFY_SSL'])),
tower_oauthtoken=dict(type='raw', no_log=True, required=False, fallback=(env_fallback, ['CONTROLLER_OAUTH_TOKEN', 'TOWER_OAUTH_TOKEN'])),
tower_config_file=dict(type='path', required=False, default=None),
)
short_params = {

View File

@ -10,12 +10,12 @@ from requests.models import Response
from unittest import mock
awx_name = 'AWX'
tower_name = 'Red Hat Automation Platform Controller'
controller_name = 'Red Hat Automation Platform Controller'
ping_version = '1.2.3'
def getTowerheader(self, header_name, default):
mock_headers = {'X-API-Product-Name': tower_name, 'X-API-Product-Version': ping_version}
mock_headers = {'X-API-Product-Name': controller_name, 'X-API-Product-Version': ping_version}
return mock_headers.get(header_name, default)
@ -107,7 +107,7 @@ def test_version_warning_strictness_controller(collection_import, silence_warnin
my_module._COLLECTION_TYPE = "controller"
my_module.get_endpoint('ping')
silence_warning.assert_called_once_with(
'You are running collection version {0} but connecting to {1} version {2}'.format(my_module._COLLECTION_VERSION, tower_name, ping_version)
'You are running collection version {0} but connecting to {1} version {2}'.format(my_module._COLLECTION_VERSION, controller_name, ping_version)
)

View File

@ -695,7 +695,7 @@
organization: Default
state: present
kind: tower
host: https://tower.example.org
host: https://controller.example.org
username: joe
password: secret
register: result

View File

@ -90,7 +90,7 @@
that:
- "result is not changed"
# Test behaviour common to all tower modules
# Test behaviour common to all controller modules
- name: Check that SSL is available and verify_ssl is enabled (task must fail)
organization:
name: Default

View File

@ -34,6 +34,12 @@
regexp: "^ NAME = 'awx.awx.controller' # REPLACE$"
replace: " NAME = '{{ collection_namespace }}.{{ collection_package }}.controller' # REPLACE"
- name: Change runtime.yml redirect destinations
replace:
path: "{{ collection_path}}/meta/runtime.yml"
regexp: "redirect: awx.awx."
replace: "redirect: '{{ collection_namespace }}.{{ collection_package }}."
- name: get list of test files
find:
paths: "{{ collection_path }}/tests/integration/targets/"