mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 01:08:48 -03:30
Adding version checking to collection
This commit is contained in:
committed by
AlanCoding
parent
30610f1a62
commit
762d8a287e
@@ -32,6 +32,8 @@ class ItemNotDefined(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class TowerModule(AnsibleModule):
|
class TowerModule(AnsibleModule):
|
||||||
|
# This gets set by the make process so whatever is in here is irrelevant
|
||||||
|
_COLLECTION_VERSION = "11.0.0"
|
||||||
url = None
|
url = None
|
||||||
honorred_settings = ('host', 'username', 'password', 'verify_ssl', 'oauth_token')
|
honorred_settings = ('host', 'username', 'password', 'verify_ssl', 'oauth_token')
|
||||||
host = '127.0.0.1'
|
host = '127.0.0.1'
|
||||||
@@ -95,6 +97,9 @@ class TowerModule(AnsibleModule):
|
|||||||
|
|
||||||
self.session = Request(cookies=CookieJar(), validate_certs=self.verify_ssl)
|
self.session = Request(cookies=CookieJar(), validate_certs=self.verify_ssl)
|
||||||
|
|
||||||
|
# Load the ping page and check the module
|
||||||
|
self.check_version()
|
||||||
|
|
||||||
def load_config_files(self):
|
def load_config_files(self):
|
||||||
# Load configs like TowerCLI would have from least import to most
|
# Load configs like TowerCLI would have from least import to most
|
||||||
config_files = ['/etc/tower/tower_cli.cfg', join(expanduser("~"), ".{0}".format(self.config_name))]
|
config_files = ['/etc/tower/tower_cli.cfg', join(expanduser("~"), ".{0}".format(self.config_name))]
|
||||||
@@ -434,15 +439,13 @@ class TowerModule(AnsibleModule):
|
|||||||
# If we have neither of these, then we can try un-authenticated access
|
# If we have neither of these, then we can try un-authenticated access
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
|
|
||||||
def default_check_mode(self):
|
def check_version(self):
|
||||||
'''Execute check mode logic for Ansible Tower modules'''
|
# Load the ping page
|
||||||
if self.check_mode:
|
response = self.get_endpoint('ping')
|
||||||
try:
|
|
||||||
result = self.get_endpoint('ping')
|
|
||||||
self.exit_json(**{'changed': True, 'tower_version': '{0}'.format(result['json']['version'])})
|
|
||||||
except(Exception) as excinfo:
|
|
||||||
self.fail_json(changed=False, msg='Failed check mode: {0}'.format(excinfo))
|
|
||||||
|
|
||||||
|
if self._COLLECTION_VERSION != response['json']['version']:
|
||||||
|
self.warn("You are running collection version {0} but connecting to tower version {1}".format(self._COLLECTION_VERSION, response['json']['version']))
|
||||||
|
|
||||||
def delete_if_needed(self, existing_item, on_delete=None):
|
def delete_if_needed(self, existing_item, on_delete=None):
|
||||||
# This will exit from the module on its own.
|
# This will exit from the module on its own.
|
||||||
# If the method successfully deletes an item and on_delete param is defined,
|
# If the method successfully deletes an item and on_delete param is defined,
|
||||||
|
|||||||
@@ -8,6 +8,12 @@
|
|||||||
collection_version: 0.0.1 # not for updating, pass in extra_vars
|
collection_version: 0.0.1 # not for updating, pass in extra_vars
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Set the collection version in the tower_api.py file
|
||||||
|
replace:
|
||||||
|
path: "{{ playbook_dir }}/plugins/module_utils/tower_api.py"
|
||||||
|
regexp: '^ _COLLECTION_VERSION =.*'
|
||||||
|
replace: ' _COLLECTION_VERSION = "{{ collection_version }}"'
|
||||||
|
|
||||||
- name: Do file content replacements for non-default namespace or package name
|
- name: Do file content replacements for non-default namespace or package name
|
||||||
block:
|
block:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user