import os
import re
import shlex
import subprocess as sp
import time
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common_info import need_skip_sys_package
def check_nexus_start_status(module, timeout=600):
nexus_status_file = os.path.expanduser("~/.local/nexus.sentinel")
start = 0
while start <= timeout:
if os.path.exists(nexus_status_file):
return ""
start += 1
time.sleep(1)
return module.fail_json(msg="nexus start failed", rc=1, changed=True)
def check_repo_index(module, os_and_arch, timeout=120):
start = 0
while start <= timeout:
check_log_cmd = "docker logs nexus"
result = sp.Popen(
shlex.split(check_log_cmd),
shell=False,
universal_newlines=True,
stderr=sp.PIPE,
stdout=sp.PIPE,
)
out, _ = result.communicate()
if re.search(r"Finished rebuilding .* {}".format(os_and_arch), out):
return module.exit_json(rc=0, changed=True)
start += 1
time.sleep(1)
return module.fail_json(
msg="Please ensure that the system dependencies for {} have been downloaded".format(os_and_arch),
rc=1,
changed=True,
)
def main():
module = AnsibleModule(argument_spec=dict(os_and_arch=dict(type="str", required=True)))
os_and_arch = module.params["os_and_arch"]
if need_skip_sys_package(os_and_arch):
return module.exit_json(rc=0, changed=True)
check_nexus_start_status(module)
if not os_and_arch.startswith(("Ubuntu", "Debian", "veLinux")):
check_repo_index(module, os_and_arch)
return module.exit_json(rc=0, changed=True)
if __name__ == "__main__":
main()