mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #5720 from mschurenko/devel
added random sleep option to ansible-pull
This commit is contained in:
commit
71977bfe71
1 changed files with 16 additions and 1 deletions
|
@ -44,6 +44,8 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
import datetime
|
import datetime
|
||||||
import socket
|
import socket
|
||||||
|
import random
|
||||||
|
import time
|
||||||
from ansible import utils
|
from ansible import utils
|
||||||
from ansible.utils import cmd_functions
|
from ansible.utils import cmd_functions
|
||||||
from ansible import errors
|
from ansible import errors
|
||||||
|
@ -102,6 +104,8 @@ def main(args):
|
||||||
help='purge checkout after playbook run')
|
help='purge checkout after playbook run')
|
||||||
parser.add_option('-o', '--only-if-changed', dest='ifchanged', default=False, action='store_true',
|
parser.add_option('-o', '--only-if-changed', dest='ifchanged', default=False, action='store_true',
|
||||||
help='only run the playbook if the repository has been updated')
|
help='only run the playbook if the repository has been updated')
|
||||||
|
parser.add_option('-s', '--sleep', dest='sleep', default=None,
|
||||||
|
help='sleep for random interval (between 0 and n number of seconds) before starting. this is a useful way to disperse git requests')
|
||||||
parser.add_option('-f', '--force', dest='force', default=False,
|
parser.add_option('-f', '--force', dest='force', default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='run the playbook even if the repository could '
|
help='run the playbook even if the repository could '
|
||||||
|
@ -164,7 +168,18 @@ def main(args):
|
||||||
inv_opts, base_opts, options.module_name, repo_opts
|
inv_opts, base_opts, options.module_name, repo_opts
|
||||||
)
|
)
|
||||||
|
|
||||||
# RUN THE CHECKOUT COMMAND
|
if options.sleep:
|
||||||
|
try:
|
||||||
|
secs = random.randint(0,int(options.sleep));
|
||||||
|
except ValueError:
|
||||||
|
parser.error("%s is not a number." % options.sleep)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
print >>sys.stderr, "Sleeping for %d seconds..." % secs
|
||||||
|
time.sleep(secs);
|
||||||
|
|
||||||
|
|
||||||
|
# RUN THe CHECKOUT COMMAND
|
||||||
rc, out, err = cmd_functions.run_cmd(cmd, live=True)
|
rc, out, err = cmd_functions.run_cmd(cmd, live=True)
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
|
|
Loading…
Reference in a new issue