diff --git a/_dependencies/library/blockdevmap.py b/_dependencies/library/blockdevmap.py index 3c10351e..1017c981 100644 --- a/_dependencies/library/blockdevmap.py +++ b/_dependencies/library/blockdevmap.py @@ -252,6 +252,12 @@ except: pass +# FileNotFoundError does not exist in python2 - it is an IOError +try: + FileNotFoundError +except NameError: + FileNotFoundError = IOError + try: from urllib.request import urlopen except ImportError: @@ -412,9 +418,9 @@ def __init__(self, **kwds): response__block_device_mapping = urlopen('http://169.254.169.254/latest/meta-data/block-device-mapping/') block_device_mappings = response__block_device_mapping.read().decode().split("\n") for block_device_mappings__ephemeral_id in [dev for dev in block_device_mappings if dev.startswith('ephemeral')]: - with urlopen("http://169.254.169.254/latest/meta-data/block-device-mapping/" + block_device_mappings__ephemeral_id) as response__ephemeral_device: - block_device_mappings__ephemeral_mapped = response__ephemeral_device.read().decode() - instance_store_map.append({'ephemeral_id': block_device_mappings__ephemeral_id, 'ephemeral_map': block_device_mappings__ephemeral_mapped}) + response__ephemeral_device = urlopen("http://169.254.169.254/latest/meta-data/block-device-mapping/" + block_device_mappings__ephemeral_id) + block_device_mappings__ephemeral_mapped = response__ephemeral_device.read().decode() + instance_store_map.append({'ephemeral_id': block_device_mappings__ephemeral_id, 'ephemeral_map': block_device_mappings__ephemeral_mapped}) instance_store_count = 0 self.device_map = self.get_lsblk() @@ -473,21 +479,17 @@ def main(): if not (len(sys.argv) > 1 and sys.argv[1] == "console"): module = AnsibleModule(argument_spec={"cloud_type": {"type": "str", "required": True, "choices": ['aws', 'gcp', 'azure', 'lsblk']}}, supports_check_mode=True) else: - # For testing without Ansible (e.g on Windows) - class cDummyAnsibleModule(): - params = {"cloud_type": "azure"} - + class cDummyAnsibleModule(): # For testing without Ansible (e.g on Windows) + def __init__(self): + self.params={} def exit_json(self, changed, **kwargs): print(changed, json.dumps(kwargs, sort_keys=True, indent=4, separators=(',', ': '))) - - def warn(self, msg): - print("[WARNING]: " + msg) - def fail_json(self, msg): print("Failed: " + msg) exit(1) module = cDummyAnsibleModule() + module.params = {"cloud_type": sys.argv[2]} if module.params['cloud_type'] == 'aws': blockdevmap = cAwsMapper(module=module) @@ -504,4 +506,4 @@ def fail_json(self, msg): if __name__ == '__main__': - main() + main() \ No newline at end of file diff --git a/_dependencies/tasks/main.yml b/_dependencies/tasks/main.yml index 14106173..80db1ae5 100644 --- a/_dependencies/tasks/main.yml +++ b/_dependencies/tasks/main.yml @@ -30,7 +30,7 @@ - name: Preflight check block: - - assert: { that: "ansible_version.full is version_compare('2.9', '>=')", fail_msg: "Ansible >=2.9 required." } + - assert: { that: "ansible_version.full is version_compare('2.9.6', '>=') and ansible_version.full is version_compare('2.10.6', '<=')", fail_msg: "2.10.6 >= Ansible >= 2.9.6 required." } #2.10.7 has issue with AWS DNS: https://github.com/ansible-collections/community.aws/issues/523 - assert: { that: "app_name is defined and app_name != ''", fail_msg: "Please define app_name" } - assert: { that: "app_class is defined and app_class != ''", fail_msg: "Please define app_class" } - assert: { that: "cluster_vars is defined", fail_msg: "Please define cluster_vars" } diff --git a/redeploy/__common/tasks/powerchange_vms_azure.yml b/redeploy/__common/tasks/powerchange_vms_azure.yml deleted file mode 100644 index c49996e9..00000000 --- a/redeploy/__common/tasks/powerchange_vms_azure.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- - -- name: "powerchange_vms/azure | hosts_to_powerchange (to {{powerchange_new_state}})" - debug: msg="{{hosts_to_powerchange}}" - -- name: "powerchange_vms/azure | {{powerchange_new_state}} VM(s) and set maintenance_mode=true (if stopping)" - block: - - name: "powerchange_vms/azure | {{powerchange_new_state}} VMs asynchronously and set maintenance_mode=true (if stopping)" - azure.azcollection.azure_rm_virtualmachine: - client_id: "{{cluster_vars[buildenv].azure_client_id}}" - secret: "{{cluster_vars[buildenv].azure_secret}}" - subscription_id: "{{cluster_vars[buildenv].azure_subscription_id}}" - tenant: "{{cluster_vars[buildenv].azure_tenant}}" - resource_group: "{{cluster_vars[buildenv].azure_resource_group}}" - append_tags: yes - name: "{{ item.name }}" - tags: "{% if powerchange_new_state == 'stop' %}{'maintenance_mode': 'true'}{% else %}{{omit}}{% endif %}" - started: "{% if powerchange_new_state == 'stop' %}no{% else %}yes{% endif %}" - zones: ["{{ (item.regionzone.split('-'))[1] }}"] - register: r__azure_rm_virtualmachine - with_items: "{{ hosts_to_powerchange }}" - async: 7200 - poll: 0 - - - name: "powerchange_vms/azure | Wait for VM(s) to {{powerchange_new_state}}" - async_status: - jid: "{{ item.ansible_job_id }}" - register: async_jobs - until: async_jobs.finished - retries: 300 - with_items: "{{r__azure_rm_virtualmachine.results}}" - when: hosts_to_powerchange | length diff --git a/redeploy/__common/tasks/powerchange_vms_esxifree.yml b/redeploy/__common/tasks/powerchange_vms_esxifree.yml deleted file mode 100644 index c62d3593..00000000 --- a/redeploy/__common/tasks/powerchange_vms_esxifree.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- - -- name: "powerchange_vms/esxifree | hosts_to_powerchange (to {{powerchange_new_state}})" - debug: msg="{{hosts_to_powerchange}}" - -- name: "powerchange_vms/esxifree | {{powerchange_new_state}} VM(s) and set maintenance_mode=true" - block: - - name: powerchange_vms/esxifree | Set maintenance_mode=true (if stopping) - esxifree_guest: - hostname: "{{ cluster_vars.esxi_ip }}" - username: "{{ cluster_vars.username }}" - password: "{{ cluster_vars.password }}" - name: "{{item.name}}" - state: unchanged - annotation: "{{ item.tagslabels | combine({'maintenance_mode': 'true'}) }}" - with_items: "{{ hosts_to_powerchange }}" - when: "powerchange_new_state == 'stop'" - - - name: "powerchange_vms/esxifree | {{powerchange_new_state}} VMs asynchronously" - esxifree_guest: - hostname: "{{ cluster_vars.esxi_ip }}" - username: "{{ cluster_vars.username }}" - password: "{{ cluster_vars.password }}" - name: "{{item.name}}" - state: "{% if powerchange_new_state == 'stop' %}shutdownguest{% else %}poweredon{% endif %}" - with_items: "{{ hosts_to_powerchange }}" - when: hosts_to_powerchange | length - \ No newline at end of file