Serko
Serko

Reputation: 321

Ansible command execution error

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?

Upvotes: 2

Views: 803

Answers (1)

ydaetskcoR
ydaetskcoR

Reputation: 56877

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.

Upvotes: 4

Related Questions