ansible-collections / ibm_zos_core

Red Hat Ansible Certified Content for IBM Z
75 stars 44 forks source link

[Enhancement] Allow zos_copy to wait for a data set lock #1491

Closed roded closed 1 month ago

roded commented 2 months ago

Is there an existing issue for this?

Enhancement or feature description

zos_copy currently supports force_lock to get around copying into data sets which are locked by other processes. As mentioned in the documentation, using force_lock can cause race conditions and data loss.

It would be useful if zos_copy would support waiting for a lock for a certain amount of time.

Ansible module

zos_copy

richp405 commented 1 month ago

Iniital discussion concludes we can address this with a playbook script. Fernando will respond to see if that is acceptable.

fernandofloresg commented 1 month ago

Hi @roded thanks for the suggestion. We are taking this conversation internally to review benefits and decide on it. In meantime, I'm sure this functionality can be achieved from ansible itself by retrying a task until a condition is met

    - name: Copy to dest data set and retry is data set is locked
      zos_copy:
        src: "./files/file.txt"
        dest: "{{ PDS_DATA_SET }}(FILE)"
      register: result
      retries: 10
      delay: 5

You can add until keyword to define a check on specific case, like until: result.msg.find("a task is accessing the data set.") == -1. If until is not specified, the task will retry until the task succeeds but at most retries times.

roded commented 1 month ago

@fernandofloresg Thanks, I'll give it a shot.

roded commented 1 month ago

@fernandofloresg Your solution works well enough for my purposes. I don't mind closing this ticket in light of it.