It is possible to async a local_action in ansible? -
i'm using ansible provision vagrant machines. want playbook uncompress database dump, import in vm , recompress back.
in "normal" mode not big deal, since dumps can pretty big uncompress/compress operation take lots of time. use "fire , forget" method described here https://docs.ansible.com/playbooks_async.html
the idea is:
- "fire , forget" dump bunzip
- [ other operations package install, configurations ecc]
- get bunzip
- import dump
- fire , forget dump recompression
if attempt bunzip using local_action
dies error: unexpected error: unable determine jid
it possible async local task?
edit
tasks list example
# start async unzip - name: bunzip dump command: bunzip2 /vagrant/vagrant_provision/dump.sql.bz2 async: 10000 poll: 0 register: bunzip_status #[... other things ...] # connect unzip , wait end - name: check dump bunzip async_status: jid={{ bunzip_status.ansible_job_id }} register: bunzip_result until: bunzip_result.finished retries: 80 #[... import db ...] # fire , forget dump recompression - name: recompress dump command: bzip2 /vagrant/vagrant_provision/dump.sql async: 10000 poll: 0
now.. since i'm using provision vagrant environment partially solved putting playbook , files inside vagrant shared folder , referencing them absolute path, , works.
but question is: possible async local_action
(or delegate_to
)?
in case use of local_action
instead archive/unarchive remotely allows me use cpus (4 versus 1 assigned vm) operations , can shutdown vm during final recompression without having wait finish.
i've gotten point make use of gnu screen whenever want background/async command in ansible can verify command running properly.
given you're describing you'd need come way notify ansible when you've reached step #3. you'd want create temporary flag file ansible can for. describe i'd along these lines:
first, i'd create wrapper script unbzip file make things bit cleaner. create flag file mentioned when bunzip complete. here's bare-bones example:
#!/bin/bash rm -f /tmp/bunzip.done bunzip /path/to/file.bz2 touch /tmp/bunzip.done exit
then i'd execute within ansible in screen session (i use sudo in example since typically sudo screen sessions specific user):
- name: invoke bunzip script local_action: command /usr/bin/screen -d -m sudo -u someuser /path/to/bzip_script.sh async: true poll: 0
at point can whatever need within ansible. once step #3 want this:
- name: wait bunzip if still running local_action: wait_for path=/tmp/bunzip.done state=present
as long wait_for script returns without error should able safely reference bunzipped data @ point. wait_for defaults 300 second timeout, may need increase if expect bunzip take longer.
Comments
Post a Comment