Adding version checking to collection

This commit is contained in:
John Westcott IV 2020-04-17 12:58:17 -04:00 committed by AlanCoding
parent 30610f1a62
commit 762d8a287e
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
2 changed files with 17 additions and 8 deletions

View File

@ -32,6 +32,8 @@ class ItemNotDefined(Exception):
class TowerModule(AnsibleModule):
# This gets set by the make process so whatever is in here is irrelevant
_COLLECTION_VERSION = "11.0.0"
url = None
honorred_settings = ('host', 'username', 'password', 'verify_ssl', 'oauth_token')
host = '127.0.0.1'
@ -95,6 +97,9 @@ class TowerModule(AnsibleModule):
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):
# 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))]
@ -434,15 +439,13 @@ class TowerModule(AnsibleModule):
# If we have neither of these, then we can try un-authenticated access
self.authenticated = True
def default_check_mode(self):
'''Execute check mode logic for Ansible Tower modules'''
if self.check_mode:
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))
def check_version(self):
# Load the ping page
response = self.get_endpoint('ping')
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):
# This will exit from the module on its own.
# If the method successfully deletes an item and on_delete param is defined,

View File

@ -8,6 +8,12 @@
collection_version: 0.0.1 # not for updating, pass in extra_vars
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
block: