2

I have a bash script, which I execute on a node using Ansible.

- name : execute the script for uploading www files
  shell: /root/upload_www.sh

Part of the script is executing:

ssh -t -o StrictHostKeyChecking=no -i $key user@$backupsrv "sudo rsync -ravzhe \"ssh -o StrictHostKeyChecking=no -i $key\" /var/www/html user@$source:/var/www/"

That script executes very long time (about 3 hours, because there are rsync tasks with about 80gb of data and other logic) and the Ansible task finishes with an error message: "Killed" but the script continues to execute and all tasks in that script do eventually finish successfully.

On the Ansible host after running the command ansible-playbook www.yml I get the following output:

# echo $?
137

How can I wait for my script to end properly?

1 Answer 1

4

You could make your task an asynchronous action instead by adding the async: "{{ max_wait_time }}"option:

- name : execute the script for uploading www files
  shell: /root/upload_www.sh
  async: 10800 # max wait of 3 hours in seconds
  poll: 300 # check for completion every 300 seconds

However, I'd be wary of using the asynchronous action for such a long time period and whether you might be better off with a different approach altogether but it's difficult to suggest a better way of doing things without knowing the problem you are trying to solve.

Sign up to request clarification or add additional context in comments.

1 Comment

The reason was in memory less: ssh -t -o StrictHostKeyChecking=no -i $key user@$backupsrv "sudo rsync -ravzhe \"ssh -o StrictHostKeyChecking=no -i $key\" /var/www/html user@$source:/var/www/" > /dev/null 2>&1 All output from the node was located in ansible host, there was many files, so linux killed that process. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.