# Buggy code
def run_pexpect(
    args,
    cwd,
    env,
    logfile,
    cancelled_callback=None,
    expect_passwords={},
    extra_update_fields=None,
    idle_timeout=None,
    job_timeout=0,
    pexpect_timeout=5,
    proot_cmd="bwrap",
):
    """
    Run the given command using pexpect to capture output and provide
    passwords when requested.

    :param args:                a list of `subprocess.call`-style arguments
                                representing a subprocess e.g., ['ls', '-la']
    :param cwd:                 the directory in which the subprocess should
                                run
    :param env:                 a dict containing environment variables for the
                                subprocess, ala `os.environ`
    :param logfile:             a file-like object for capturing stdout
    :param cancelled_callback:  a callable - which returns `True` or `False`
                                - signifying if the job has been prematurely
                                  cancelled
    :param expect_passwords:    a dict of regular expression password prompts
                                to input values, i.e., {r'Password:\s*?$':
                                'some_password'}
    :param extra_update_fields: a dict used to specify DB fields which should
                                be updated on the underlying model
                                object after execution completes
    :param idle_timeout         a timeout (in seconds); if new output is not
                                sent to stdout in this interval, the process
                                will be terminated
    :param job_timeout          a timeout (in seconds); if the total job runtime
                                exceeds this, the process will be killed
    :param pexpect_timeout      a timeout (in seconds) to wait on
                                `pexpect.spawn().expect()` calls
    :param proot_cmd            the command used to isolate processes, `bwrap`

    Returns a tuple (status, return_code) i.e., `('successful', 0)`
    """
    expect_passwords[pexpect.TIMEOUT] = None
    expect_passwords[pexpect.EOF] = None

    if not isinstance(expect_passwords, collections.OrderedDict):
        # We iterate over `expect_passwords.keys()` and
        # `expect_passwords.values()` separately to map matched inputs to
        # patterns and choose the proper string to send to the subprocess;
        # enforce usage of an OrderedDict so that the ordering of elements in
        # `keys()` matches `values()`.
        expect_passwords = collections.OrderedDict(expect_passwords)
    password_patterns = expect_passwords.keys()
    password_values = expect_passwords.values()

    child = pexpect.spawn(
        args[0],
        args[1:],
        cwd=cwd,
        env=env,
        ignore_sighup=True,
        encoding="utf-8",
        echo=False,
        poll=True,
    )
    child.logfile_read = logfile
    canceled = False
    timed_out = False
    errored = False
    last_stdout_update = time.time()

    job_start = time.time()
    while child.isalive():
        result_id = child.expect(
            password_patterns, timeout=pexpect_timeout, searchwindowsize=100
        )
        password = password_values[result_id]
        if password is not None:
            child.sendline(password)
            last_stdout_update = time.time()
        if cancelled_callback:
            try:
                canceled = cancelled_callback()
            except Exception:
                logger.exception(
                    "Could not check cancel callback - canceling immediately"
                )
                if isinstance(extra_update_fields, dict):
                    extra_update_fields["job_explanation"] = (
                        "System error during job execution, check system logs"
                    )
                errored = True
        else:
            canceled = False
        if (
            not canceled
            and job_timeout != 0
            and (time.time() - job_start) > job_timeout
        ):
            timed_out = True
            if isinstance(extra_update_fields, dict):
                extra_update_fields["job_explanation"] = "Job terminated due to timeout"
        if canceled or timed_out or errored:
            handle_termination(child.pid, child.args, proot_cmd, is_cancel=canceled)
        if idle_timeout and (time.time() - last_stdout_update) > idle_timeout:
            child.close(True)
            canceled = True
    if errored:
        return "error", child.exitstatus
    elif canceled:
        return "canceled", child.exitstatus
    elif child.exitstatus == 0 and not timed_out:
        return "successful", child.exitstatus
    else:
        return "failed", child.exitstatus


# Traceback (RuntimeError)
2018-06-08T09:44:25.203865658Z Using /etc/ansible/ansible.cfg as config file
2018-06-08T09:44:25.924522979Z 127.0.0.1 | SUCCESS => {
2018-06-08T09:44:25.924550559Z     "changed": false, 
2018-06-08T09:44:25.924554135Z     "elapsed": 0, 
2018-06-08T09:44:25.924557026Z     "path": null, 
2018-06-08T09:44:25.924559897Z     "port": 5432, 
2018-06-08T09:44:25.924562551Z     "search_regex": null, 
2018-06-08T09:44:25.924565301Z     "state": "started"
2018-06-08T09:44:25.924568201Z }
2018-06-08T09:44:26.233707860Z Using /etc/ansible/ansible.cfg as config file
2018-06-08T09:44:26.922357723Z 127.0.0.1 | SUCCESS => {
2018-06-08T09:44:26.922393193Z     "changed": false, 
2018-06-08T09:44:26.922397506Z     "elapsed": 0, 
2018-06-08T09:44:26.922400662Z     "path": null, 
2018-06-08T09:44:26.922403883Z     "port": 11211, 
2018-06-08T09:44:26.922406969Z     "search_regex": null, 
2018-06-08T09:44:26.922410214Z     "state": "started"
2018-06-08T09:44:26.922413438Z }
2018-06-08T09:44:27.339105885Z Using /etc/ansible/ansible.cfg as config file
2018-06-08T09:44:28.131366751Z 127.0.0.1 | SUCCESS => {
2018-06-08T09:44:28.131407560Z     "changed": false, 
2018-06-08T09:44:28.131416179Z     "elapsed": 0, 
2018-06-08T09:44:28.131421344Z     "path": null, 
2018-06-08T09:44:28.131426416Z     "port": 5672, 
2018-06-08T09:44:28.131431649Z     "search_regex": null, 
2018-06-08T09:44:28.131436075Z     "state": "started"
2018-06-08T09:44:28.131440581Z }
2018-06-08T09:44:28.516278745Z Using /etc/ansible/ansible.cfg as config file
2018-06-08T09:44:29.410034950Z 127.0.0.1 | SUCCESS => {
2018-06-08T09:44:29.410088710Z     "changed": true, 
2018-06-08T09:44:29.410094849Z     "db": "awx"
2018-06-08T09:44:29.410098297Z }
2018-06-08T09:44:32.007342016Z Operations to perform:
2018-06-08T09:44:32.007383063Z   Apply all migrations: auth, conf, contenttypes, djcelery, main, network_ui, oauth2_provider, sessions, sites, social_django, sso, taggit
2018-06-08T09:44:32.007390575Z Running migrations:
2018-06-08T09:44:32.024935105Z   Applying contenttypes.0001_initial... OK
2018-06-08T09:44:32.042836650Z   Applying contenttypes.0002_remove_content_type_name... OK
2018-06-08T09:44:32.127353303Z   Applying auth.0001_initial... OK
2018-06-08T09:44:32.145135123Z   Applying auth.0002_alter_permission_name_max_length... OK
2018-06-08T09:44:32.165300076Z   Applying auth.0003_alter_user_email_max_length... OK
2018-06-08T09:44:32.178506403Z   Applying auth.0004_alter_user_username_opts... OK
2018-06-08T09:44:32.198106968Z   Applying auth.0005_alter_user_last_login_null... OK
2018-06-08T09:44:32.203816548Z   Applying auth.0006_require_contenttypes_0002... OK
2018-06-08T09:44:32.218492670Z   Applying auth.0007_alter_validators_add_error_messages... OK
2018-06-08T09:44:32.234294362Z   Applying auth.0008_alter_user_username_max_length... OK
2018-06-08T09:44:32.285106264Z   Applying taggit.0001_initial... OK
2018-06-08T09:44:32.302759193Z   Applying taggit.0002_auto_20150616_2121... OK
2018-06-08T09:44:44.838536570Z   Applying main.0001_initial... OK
2018-06-08T09:45:05.662400582Z   Applying main.0002_squashed_v300_release... OK
2018-06-08T09:45:10.106556771Z   Applying main.0003_squashed_v300_v303_updates... OK
2018-06-08T09:45:35.586672374Z   Applying main.0004_squashed_v310_release... OK
2018-06-08T09:45:35.807040763Z   Applying conf.0001_initial... OK
2018-06-08T09:45:36.001122421Z   Applying conf.0002_v310_copy_tower_settings... OK
2018-06-08T09:45:36.137892279Z   Applying conf.0003_v310_JSONField_changes... OK
2018-06-08T09:45:36.366005723Z   Applying conf.0004_v320_reencrypt... OK
2018-06-08T09:45:36.595713184Z   Applying djcelery.0001_initial... OK
2018-06-08T09:45:36.626829028Z   Applying sessions.0001_initial... OK
2018-06-08T09:45:38.322220008Z   Applying main.0005_squashed_v310_v313_updates... OK
2018-06-08T09:46:02.372829148Z   Applying main.0006_v320_release... OK
2018-06-08T09:46:02.952111866Z 2018-06-08 09:46:02,951 DEBUG    awx.main.migrations Removing all Rackspace InventorySource from database.
2018-06-08T09:46:03.436861105Z 2018-06-08 09:46:03,436 DEBUG    awx.main.migrations Removing all Azure Credentials from database.
2018-06-08T09:46:03.693091536Z 2018-06-08 09:46:03,692 DEBUG    awx.main.migrations Removing all Azure InventorySource from database.
2018-06-08T09:46:03.930165070Z 2018-06-08 09:46:03,929 DEBUG    awx.main.migrations Removing all InventorySource that have no link to an Inventory from database.
2018-06-08T09:46:05.695018847Z 2018-06-08 09:46:05,694 DEBUG    awx.main.models.credential adding Machine credential type
2018-06-08T09:46:05.698944841Z 2018-06-08 09:46:05,698 DEBUG    awx.main.models.credential adding Source Control credential type
2018-06-08T09:46:05.703267352Z 2018-06-08 09:46:05,702 DEBUG    awx.main.models.credential adding Vault credential type
2018-06-08T09:46:05.708868367Z 2018-06-08 09:46:05,708 DEBUG    awx.main.models.credential adding Network credential type
2018-06-08T09:46:05.714614390Z 2018-06-08 09:46:05,714 DEBUG    awx.main.models.credential adding Amazon Web Services credential type
2018-06-08T09:46:05.723113588Z 2018-06-08 09:46:05,722 DEBUG    awx.main.models.credential adding OpenStack credential type
2018-06-08T09:46:05.729460063Z 2018-06-08 09:46:05,729 DEBUG    awx.main.models.credential adding VMware vCenter credential type
2018-06-08T09:46:05.735112784Z 2018-06-08 09:46:05,734 DEBUG    awx.main.models.credential adding Red Hat Satellite 6 credential type
2018-06-08T09:46:05.740621522Z 2018-06-08 09:46:05,740 DEBUG    awx.main.models.credential adding Red Hat CloudForms credential type
2018-06-08T09:46:05.747086747Z 2018-06-08 09:46:05,746 DEBUG    awx.main.models.credential adding Google Compute Engine credential type
2018-06-08T09:46:05.752800505Z 2018-06-08 09:46:05,752 DEBUG    awx.main.models.credential adding Microsoft Azure Resource Manager credential type
2018-06-08T09:46:05.757823326Z 2018-06-08 09:46:05,757 DEBUG    awx.main.models.credential adding Insights credential type
2018-06-08T09:46:05.763457411Z 2018-06-08 09:46:05,763 DEBUG    awx.main.models.credential adding Red Hat Virtualization credential type
2018-06-08T09:46:05.768385153Z 2018-06-08 09:46:05,768 DEBUG    awx.main.models.credential adding Ansible Tower credential type
2018-06-08T09:46:06.008435544Z   Applying main.0007_v320_data_migrations... OK
2018-06-08T09:46:12.933848696Z   Applying main.0008_v320_drop_v1_credential_fields... OK
2018-06-08T09:46:13.232944928Z   Applying main.0009_v322_add_setting_field_for_activity_stream... OK
2018-06-08T09:46:14.896590550Z   Applying main.0010_v322_add_ovirt4_tower_inventory... OK
2018-06-08T09:46:15.322624979Z   Applying main.0011_v322_encrypt_survey_passwords... OK
2018-06-08T09:46:15.602059828Z   Applying main.0012_v322_update_cred_types... OK
2018-06-08T09:46:18.891145025Z   Applying main.0013_v330_multi_credential... OK
2018-06-08T09:46:25.282022384Z   Applying main.0014_v330_saved_launchtime_configs... OK
2018-06-08T09:46:25.891994173Z   Applying main.0015_v330_blank_start_args... OK
2018-06-08T09:46:27.024002808Z   Applying main.0016_v330_non_blank_workflow... OK
2018-06-08T09:46:27.482027189Z   Applying main.0017_v330_move_deprecated_stdout... OK
2018-06-08T09:46:28.489212584Z   Applying main.0018_v330_add_additional_stdout_events... OK
2018-06-08T09:46:29.090407324Z   Applying main.0019_v330_custom_virtualenv... OK
2018-06-08T09:46:29.623309143Z   Applying main.0020_v330_instancegroup_policies... OK
2018-06-08T09:46:34.225422014Z   Applying main.0021_v330_declare_new_rbac_roles... OK
2018-06-08T09:46:34.969383223Z   Applying main.0022_v330_create_new_rbac_roles... OK
2018-06-08T09:46:37.280314382Z   Applying main.0023_v330_inventory_multicred... OK
2018-06-08T09:46:37.496984889Z   Applying main.0024_v330_create_user_session_membership... OK
2018-06-08T09:46:38.801332606Z   Applying main.0025_v330_add_oauth_activity_stream_registrar... OK
2018-06-08T09:46:39.122608577Z   Applying main.0026_v330_delete_authtoken... OK
2018-06-08T09:46:39.421801004Z   Applying main.0027_v330_emitted_events... OK
2018-06-08T09:46:39.791118027Z   Applying main.0028_v330_add_tower_verify... OK
2018-06-08T09:46:40.203292440Z   Applying main.0030_v330_modify_application... OK
2018-06-08T09:46:40.576987689Z   Applying main.0031_v330_encrypt_oauth2_secret... OK
2018-06-08T09:46:41.027046883Z   Applying main.0032_v330_polymorphic_delete... OK
2018-06-08T09:46:43.555485198Z   Applying main.0033_v330_oauth_help_text... OK
2018-06-08T09:46:44.503618481Z 2018-06-08 09:46:44,503 INFO     rbac_migrations Computing role roots..
2018-06-08T09:46:44.504439240Z 2018-06-08 09:46:44,504 INFO     rbac_migrations Found 0 roots in 0.000193 seconds, rebuilding ancestry map
2018-06-08T09:46:44.504553948Z 2018-06-08 09:46:44,504 INFO     rbac_migrations Rebuild completed in 0.000007 seconds
2018-06-08T09:46:44.504567198Z 2018-06-08 09:46:44,504 INFO     rbac_migrations Done.
2018-06-08T09:46:44.510720538Z   Applying main.0034_v330_delete_user_role... OK
2018-06-08T09:46:44.726854041Z   Applying main.0035_v330_more_oauth2_help_text... OK
2018-06-08T09:46:45.014445988Z   Applying main.0036_v330_credtype_remove_become_methods... OK
2018-06-08T09:46:45.430984415Z   Applying main.0037_v330_remove_legacy_fact_cleanup... OK
2018-06-08T09:46:48.512977506Z   Applying network_ui.0001_initial... OK
2018-06-08T09:46:49.792390169Z   Applying oauth2_provider.0001_initial... OK
2018-06-08T09:46:50.521797046Z   Applying oauth2_provider.0002_08_updates... OK
2018-06-08T09:46:50.777808169Z   Applying oauth2_provider.0003_auto_20160316_1503... OK
2018-06-08T09:46:51.364219303Z   Applying oauth2_provider.0004_auto_20160525_1623... OK
2018-06-08T09:46:55.938329130Z   Applying oauth2_provider.0005_auto_20170514_1141... OK
2018-06-08T09:46:55.956703684Z   Applying sites.0001_initial... OK
2018-06-08T09:46:55.980176273Z   Applying sites.0002_alter_domain_unique... OK
2018-06-08T09:46:56.550988518Z   Applying social_django.0001_initial... OK
2018-06-08T09:46:56.897441029Z   Applying social_django.0002_add_related_name... OK
2018-06-08T09:46:56.928890998Z   Applying social_django.0003_alter_email_max_length... OK
2018-06-08T09:46:57.273418609Z   Applying social_django.0004_auto_20160423_0400... OK
2018-06-08T09:46:57.325622661Z   Applying social_django.0005_auto_20160727_2333... OK
2018-06-08T09:46:57.396781204Z   Applying social_django.0006_partial... OK
2018-06-08T09:46:57.446589275Z   Applying social_django.0007_code_timestamp... OK
2018-06-08T09:46:57.489062867Z   Applying social_django.0008_partial_timestamp... OK
2018-06-08T09:46:58.327336660Z   Applying sso.0001_initial... OK
2018-06-08T09:47:00.812236111Z   Applying sso.0002_expand_provider_options... OK
2018-06-08T09:47:07.528082784Z Traceback (most recent call last):
2018-06-08T09:47:07.528235426Z   File "/usr/bin/awx-manage", line 9, in <module>
2018-06-08T09:47:07.531646889Z     load_entry_point('awx==1.0.6.15', 'console_scripts', 'awx-manage')()
2018-06-08T09:47:07.531681489Z   File "/usr/lib/python2.7/site-packages/awx/__init__.py", line 109, in manage
2018-06-08T09:47:07.531820552Z     execute_from_command_line(sys.argv)
2018-06-08T09:47:07.531849077Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
2018-06-08T09:47:07.532838889Z     utility.execute()
2018-06-08T09:47:07.532860930Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
2018-06-08T09:47:07.532868631Z     self.fetch_command(subcommand).run_from_argv(self.argv)
2018-06-08T09:47:07.532875206Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
2018-06-08T09:47:07.532881899Z     self.execute(*args, **cmd_options)
2018-06-08T09:47:07.532888291Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
2018-06-08T09:47:07.532895159Z     output = self.handle(*args, **options)
2018-06-08T09:47:07.532901461Z   File "/usr/lib/python2.7/site-packages/awx/main/management/commands/create_preload_data.py", line 47, in handle
2018-06-08T09:47:07.532927140Z     created_by=superuser)
2018-06-08T09:47:07.532933858Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
2018-06-08T09:47:07.532940729Z     return getattr(self.get_queryset(), name)(*args, **kwargs)
2018-06-08T09:47:07.532947074Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py", line 394, in create
2018-06-08T09:47:07.532953727Z     obj.save(force_insert=True, using=self.db)
2018-06-08T09:47:07.532960099Z   File "/usr/lib/python2.7/site-packages/awx/main/models/inventory.py", line 700, in save
2018-06-08T09:47:07.532966787Z     super(Host, self).save(*args, **kwargs)
2018-06-08T09:47:07.532973006Z   File "/usr/lib/python2.7/site-packages/awx/main/models/base.py", line 275, in save
2018-06-08T09:47:07.532979506Z     super(PrimordialModel, self).save(*args, **kwargs)
2018-06-08T09:47:07.532985715Z   File "/usr/lib/python2.7/site-packages/awx/main/models/base.py", line 164, in save
2018-06-08T09:47:07.533016667Z     super(CreatedModifiedModel, self).save(*args, **kwargs)
2018-06-08T09:47:07.533023094Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/base.py", line 808, in save
2018-06-08T09:47:07.533029752Z     force_update=force_update, update_fields=update_fields)
2018-06-08T09:47:07.533036137Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/base.py", line 848, in save_base
2018-06-08T09:47:07.533042899Z     update_fields=update_fields, raw=raw, using=using,
2018-06-08T09:47:07.533049199Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 193, in send
2018-06-08T09:47:07.533055855Z     for receiver in self._live_receivers(sender)
2018-06-08T09:47:07.533062097Z   File "/usr/lib/python2.7/site-packages/awx/main/signals.py", line 146, in emit_update_inventory_on_created_or_deleted
2018-06-08T09:47:07.533101465Z     update_inventory_computed_fields.delay(inventory.id, True)
2018-06-08T09:47:07.533109814Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/task.py", line 461, in delay
2018-06-08T09:47:07.533116632Z     return self.apply_async(args, kwargs)
2018-06-08T09:47:07.533122797Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/task.py", line 573, in apply_async
2018-06-08T09:47:07.533129389Z     **dict(self._get_exec_options(), **options)
2018-06-08T09:47:07.533135549Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/base.py", line 345, in send_task
2018-06-08T09:47:07.533142214Z     options = router.route(options, name, args, kwargs)
2018-06-08T09:47:07.533165187Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/routes.py", line 50, in route
2018-06-08T09:47:07.533173296Z     route = self.lookup_route(task, args, kwargs)
2018-06-08T09:47:07.533179610Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/routes.py", line 78, in lookup_route
2018-06-08T09:47:07.533186326Z     return _first_route(self.routes, task, args, kwargs)
2018-06-08T09:47:07.533192567Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/utils/functional.py", line 233, in _matcher
2018-06-08T09:47:07.533199323Z     answer = getattr(maybe_evaluate(obj), method)(*args, **kwargs)
2018-06-08T09:47:07.533205798Z   File "/usr/lib/python2.7/site-packages/awx/main/utils/ha.py", line 58, in route_for_task
2018-06-08T09:47:07.533212571Z     (changed, instance) = Instance.objects.get_or_register()
2018-06-08T09:47:07.533218890Z   File "/usr/lib/python2.7/site-packages/awx/main/managers.py", line 106, in get_or_register
2018-06-08T09:47:07.533225500Z     return (False, self.me())
2018-06-08T09:47:07.533246715Z   File "/usr/lib/python2.7/site-packages/awx/main/managers.py", line 88, in me
2018-06-08T09:47:07.533254282Z     raise RuntimeError("No instance found with the current cluster host id")
2018-06-08T09:47:07.533261053Z RuntimeError: No instance found with the current cluster host id
2018-06-08T09:55:56.011873319Z Traceback (most recent call last):
2018-06-08T09:55:56.011942768Z   File "/usr/bin/awx-manage", line 9, in <module>
2018-06-08T09:55:56.012043641Z     load_entry_point('awx==1.0.6.15', 'console_scripts', 'awx-manage')()
2018-06-08T09:55:56.012053201Z   File "/usr/lib/python2.7/site-packages/awx/__init__.py", line 109, in manage
2018-06-08T09:55:56.012056860Z     execute_from_command_line(sys.argv)
2018-06-08T09:55:56.012060093Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
2018-06-08T09:55:56.012064075Z     utility.execute()
2018-06-08T09:55:56.012067205Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
2018-06-08T09:55:56.012070604Z     self.fetch_command(subcommand).run_from_argv(self.argv)
2018-06-08T09:55:56.012094764Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
2018-06-08T09:55:56.012098928Z     self.execute(*args, **cmd_options)
2018-06-08T09:55:56.012101661Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
2018-06-08T09:55:56.012104689Z     output = self.handle(*args, **options)
2018-06-08T09:55:56.012107380Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/utils/decorators.py", line 185, in inner
2018-06-08T09:55:56.012110360Z     return func(*args, **kwargs)
2018-06-08T09:55:56.012113064Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/transaction.py", line 267, in __exit__
2018-06-08T09:55:56.012116028Z     connection.set_autocommit(True)
2018-06-08T09:55:56.012118649Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/backends/base/base.py", line 416, in set_autocommit
2018-06-08T09:55:56.012121560Z     self.run_and_clear_commit_hooks()
2018-06-08T09:55:56.012124162Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/backends/base/base.py", line 651, in run_and_clear_commit_hooks
2018-06-08T09:55:56.012127408Z     func()
2018-06-08T09:55:56.012130072Z   File "/usr/lib/python2.7/site-packages/awx/main/models/ha.py", line 203, in <lambda>
2018-06-08T09:55:56.012133118Z     connection.on_commit(lambda: apply_cluster_membership_policies.apply_async())
2018-06-08T09:55:56.012135972Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/task.py", line 573, in apply_async
2018-06-08T09:55:56.012138771Z     **dict(self._get_exec_options(), **options)
2018-06-08T09:55:56.012141442Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/base.py", line 354, in send_task
2018-06-08T09:55:56.012148106Z     reply_to=reply_to or self.oid, **options
2018-06-08T09:55:56.012180832Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/amqp.py", line 310, in publish_task
2018-06-08T09:55:56.012185276Z     **kwargs
2018-06-08T09:55:56.012187984Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/messaging.py", line 172, in publish
2018-06-08T09:55:56.012190838Z     routing_key, mandatory, immediate, exchange, declare)
2018-06-08T09:55:56.012193618Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 470, in _ensured
2018-06-08T09:55:56.012196500Z     interval_max)
2018-06-08T09:55:56.012199141Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 382, in ensure_connection
2018-06-08T09:55:56.012201985Z     interval_start, interval_step, interval_max, callback)
2018-06-08T09:55:56.012204674Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/utils/__init__.py", line 246, in retry_over_time
2018-06-08T09:55:56.012207561Z     return fun(*args, **kwargs)
2018-06-08T09:55:56.012214728Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 250, in connect
2018-06-08T09:55:56.012217666Z     return self.connection
2018-06-08T09:55:56.012220329Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 756, in connection
2018-06-08T09:55:56.012223211Z     self._connection = self._establish_connection()
2018-06-08T09:55:56.012225834Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 711, in _establish_connection
2018-06-08T09:55:56.012242588Z     conn = self.transport.establish_connection()
2018-06-08T09:55:56.012245343Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
2018-06-08T09:55:56.012248270Z     conn = self.Connection(**opts)
2018-06-08T09:55:56.012251177Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 171, in __init__
2018-06-08T09:55:56.012254081Z     (10, 10),  # start
2018-06-08T09:55:56.012256719Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/abstract_channel.py", line 67, in wait
2018-06-08T09:55:56.012259573Z     self.channel_id, allowed_methods, timeout)
2018-06-08T09:55:56.012262271Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 241, in _wait_method
2018-06-08T09:55:56.012265144Z     channel, method_sig, args, content = read_timeout(timeout)
2018-06-08T09:55:56.012267871Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 330, in read_timeout
2018-06-08T09:55:56.012270742Z     return self.method_reader.read_method()
2018-06-08T09:55:56.012273435Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
2018-06-08T09:55:56.012276280Z     raise m
2018-06-08T09:55:56.012278888Z socket.error: [Errno 104] Connection reset by peer
2018-06-08T09:55:56.011802960Z Successfully registered instance awx
2018-06-08T09:55:56.012305738Z (changed: True)
2018-06-08T10:04:42.857335051Z Traceback (most recent call last):
2018-06-08T10:04:42.857722102Z   File "/usr/bin/awx-manage", line 9, in <module>
2018-06-08T10:04:42.857739150Z     load_entry_point('awx==1.0.6.15', 'console_scripts', 'awx-manage')()
2018-06-08T10:04:42.857746411Z   File "/usr/lib/python2.7/site-packages/awx/__init__.py", line 109, in manage
2018-06-08T10:04:42.857864449Z     execute_from_command_line(sys.argv)
2018-06-08T10:04:42.857881740Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
2018-06-08T10:04:42.857913422Z     utility.execute()
2018-06-08T10:04:42.857921399Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
2018-06-08T10:04:42.863630450Z     self.fetch_command(subcommand).run_from_argv(self.argv)
2018-06-08T10:04:42.863685784Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
2018-06-08T10:04:42.863695522Z     self.execute(*args, **cmd_options)
2018-06-08T10:04:42.863700252Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
2018-06-08T10:04:42.863838268Z     output = self.handle(*args, **options)
2018-06-08T10:04:42.863851632Z   File "/usr/lib/python2.7/site-packages/awx/main/management/commands/register_queue.py", line 100, in handle
2018-06-08T10:04:42.863857055Z     (ig, created, changed) = self.get_create_update_instance_group(queuename, inst_per, inst_min)
2018-06-08T10:04:42.863879403Z   File "/usr/lib/python2.7/site-packages/awx/main/management/commands/register_queue.py", line 39, in get_create_update_instance_group
2018-06-08T10:04:42.863884889Z     (ig, created) = InstanceGroup.objects.get_or_create(name=queuename)
2018-06-08T10:04:42.863889619Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
2018-06-08T10:04:42.863894821Z     return getattr(self.get_queryset(), name)(*args, **kwargs)
2018-06-08T10:04:42.863899594Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py", line 466, in get_or_create
2018-06-08T10:04:42.863904641Z     return self._create_object_from_params(lookup, params)
2018-06-08T10:04:42.863909184Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/models/query.py", line 498, in _create_object_from_params
2018-06-08T10:04:42.863914194Z     obj = self.create(**params)
2018-06-08T10:04:42.863918696Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/transaction.py", line 267, in __exit__
2018-06-08T10:04:42.863923604Z     connection.set_autocommit(True)
2018-06-08T10:04:42.863928075Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/backends/base/base.py", line 416, in set_autocommit
2018-06-08T10:04:42.863933009Z     self.run_and_clear_commit_hooks()
2018-06-08T10:04:42.863937458Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/db/backends/base/base.py", line 651, in run_and_clear_commit_hooks
2018-06-08T10:04:42.863953420Z     func()
2018-06-08T10:04:42.863958258Z   File "/usr/lib/python2.7/site-packages/awx/main/models/ha.py", line 196, in <lambda>
2018-06-08T10:04:42.863963817Z     connection.on_commit(lambda: apply_cluster_membership_policies.apply_async())
2018-06-08T10:04:42.863968716Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/task.py", line 573, in apply_async
2018-06-08T10:04:42.863973759Z     **dict(self._get_exec_options(), **options)
2018-06-08T10:04:42.863978575Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/base.py", line 354, in send_task
2018-06-08T10:04:42.863983333Z     reply_to=reply_to or self.oid, **options
2018-06-08T10:04:42.864002311Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/app/amqp.py", line 310, in publish_task
2018-06-08T10:04:42.864007479Z     **kwargs
2018-06-08T10:04:42.864012925Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/messaging.py", line 172, in publish
2018-06-08T10:04:42.864029213Z     routing_key, mandatory, immediate, exchange, declare)
2018-06-08T10:04:42.864034611Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 470, in _ensured
2018-06-08T10:04:42.864039363Z     interval_max)
2018-06-08T10:04:42.864043798Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 382, in ensure_connection
2018-06-08T10:04:42.864048578Z     interval_start, interval_step, interval_max, callback)
2018-06-08T10:04:42.864052712Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/utils/__init__.py", line 246, in retry_over_time
2018-06-08T10:04:42.864057143Z     return fun(*args, **kwargs)
2018-06-08T10:04:42.864061366Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 250, in connect
2018-06-08T10:04:42.864066013Z     return self.connection
2018-06-08T10:04:42.864070517Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 756, in connection
2018-06-08T10:04:42.864074967Z     self._connection = self._establish_connection()
2018-06-08T10:04:42.864079252Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 711, in _establish_connection
2018-06-08T10:04:42.864083777Z     conn = self.transport.establish_connection()
2018-06-08T10:04:42.864088127Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
2018-06-08T10:04:42.864092776Z     conn = self.Connection(**opts)
2018-06-08T10:04:42.864115176Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 171, in __init__
2018-06-08T10:04:42.864120796Z     (10, 10),  # start
2018-06-08T10:04:42.864125154Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/abstract_channel.py", line 67, in wait
2018-06-08T10:04:42.864129491Z     self.channel_id, allowed_methods, timeout)
2018-06-08T10:04:42.864133925Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 241, in _wait_method
2018-06-08T10:04:42.864138347Z     channel, method_sig, args, content = read_timeout(timeout)
2018-06-08T10:04:42.864142641Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 330, in read_timeout
2018-06-08T10:04:42.864147139Z     return self.method_reader.read_method()
2018-06-08T10:04:42.864151820Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
2018-06-08T10:04:42.864156287Z     raise m
2018-06-08T10:04:42.864160393Z socket.error: [Errno 104] Connection reset by peer
2018-06-08T10:04:43.089572693Z 2018-06-08 10:04:43,089 CRIT Supervisor is running as root.  Privileges were not dropped because no user is specified in the config file.  If you intend to run as root, you can set user=root in the config file to avoid this message.
2018-06-08T10:04:43.103396894Z 2018-06-08 10:04:43,102 INFO RPC interface 'supervisor' initialized
2018-06-08T10:04:43.103508203Z 2018-06-08 10:04:43,102 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2018-06-08T10:04:43.107666094Z 2018-06-08 10:04:43,103 INFO supervisord started with pid 186
2018-06-08T10:04:44.109027319Z 2018-06-08 10:04:44,106 INFO spawned: 'awx-config-watcher' with pid 189
2018-06-08T10:04:44.111463250Z 2018-06-08 10:04:44,108 INFO spawned: 'celery' with pid 190
2018-06-08T10:04:44.112582351Z 2018-06-08 10:04:44,111 INFO spawned: 'channels-worker' with pid 191
2018-06-08T10:04:44.113479225Z 2018-06-08 10:04:44,113 INFO spawned: 'callback-receiver' with pid 192
2018-06-08T10:04:44.190085858Z READY
2018-06-08T10:04:45.191520064Z 2018-06-08 10:04:45,191 INFO success: awx-config-watcher entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-06-08T10:04:45.191590284Z 2018-06-08 10:04:45,191 INFO success: celery entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-06-08T10:04:45.191732227Z 2018-06-08 10:04:45,191 INFO success: channels-worker entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-06-08T10:04:45.191755811Z 2018-06-08 10:04:45,191 INFO success: callback-receiver entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-06-08T10:04:46.694300426Z 2018-06-08 10:04:46,693 INFO     awx.main.tasks Syncing Schedules
2018-06-08T10:04:46.724503713Z 2018-06-08 10:04:46,724 - INFO - runworker - Using single-threaded worker.
2018-06-08T10:04:46.726218420Z 2018-06-08 10:04:46,724 - INFO - runworker - Running worker against channel layer default (asgi_amqp.core.AMQPChannelLayer)
2018-06-08T10:04:46.726245432Z 2018-06-08 10:04:46,725 - INFO - worker - Listening on channels websocket.connect, websocket.disconnect, websocket.receive
2018-06-08T10:04:46.744816098Z /var/lib/awx/venv/awx/lib/python2.7/site-packages/celery/platforms.py:812: RuntimeWarning: You are running the worker with superuser privileges, which is
2018-06-08T10:04:46.744883126Z absolutely not recommended!
2018-06-08T10:04:46.744891139Z 
2018-06-08T10:04:46.744894409Z Please specify a different user using the -u option.
2018-06-08T10:04:46.744897721Z 
2018-06-08T10:04:46.744901021Z User information: uid=0 euid=0 gid=0 egid=0
2018-06-08T10:04:46.744904159Z 
2018-06-08T10:04:46.744907146Z   uid=uid, euid=euid, gid=gid, egid=egid,
2018-06-08T10:04:46.752662535Z [2018-06-08 10:04:46,752: DEBUG/MainProcess] | Worker: Preparing bootsteps.
2018-06-08T10:04:46.756751333Z [2018-06-08 10:04:46,756: DEBUG/MainProcess] | Worker: Building graph...
2018-06-08T10:04:46.757722612Z [2018-06-08 10:04:46,757: DEBUG/MainProcess] | Worker: New boot order: {Timer, Hub, Queues (intra), Pool, Autoscaler, StateDB, Autoreloader, Beat, Consumer}
2018-06-08T10:04:46.763787806Z 2018-06-08 10:04:46,759 WARNING  awx.main.tasks celery worker dynamic --autoscale=50,4
2018-06-08T10:04:46.772987173Z [2018-06-08 10:04:46,771: DEBUG/MainProcess] | Consumer: Preparing bootsteps.
2018-06-08T10:04:46.773019504Z [2018-06-08 10:04:46,772: DEBUG/MainProcess] | Consumer: Building graph...
2018-06-08T10:04:46.774322348Z [2018-06-08 10:04:46,773: DEBUG/MainProcess] | Consumer: New boot order: {Connection, Events, Mingle, Tasks, Control, Gossip, Agent, Heart, event loop}
2018-06-08T10:04:46.781905347Z 2018-06-08 10:04:46,781 WARNING  awx.main.tasks Set hostname to celery@awx
2018-06-08T10:04:46.787553266Z [2018-06-08 10:04:46,786: DEBUG/MainProcess] | Worker: Starting Hub
2018-06-08T10:04:46.787596457Z [2018-06-08 10:04:46,786: DEBUG/MainProcess] ^-- substep ok
2018-06-08T10:04:46.787606749Z [2018-06-08 10:04:46,786: DEBUG/MainProcess] | Worker: Starting Pool
2018-06-08T10:04:47.298666597Z [2018-06-08 10:04:47,297: DEBUG/MainProcess] ^-- substep ok
2018-06-08T10:04:47.298755079Z [2018-06-08 10:04:47,297: DEBUG/MainProcess] | Worker: Starting Autoscaler
2018-06-08T10:04:47.299604429Z [2018-06-08 10:04:47,298: DEBUG/MainProcess] ^-- substep ok
2018-06-08T10:04:47.299622371Z [2018-06-08 10:04:47,298: DEBUG/MainProcess] | Worker: Starting Beat
2018-06-08T10:04:47.306812616Z [2018-06-08 10:04:47,301: DEBUG/MainProcess] ^-- substep ok
2018-06-08T10:04:47.306834572Z [2018-06-08 10:04:47,302: DEBUG/MainProcess] | Worker: Starting Consumer
2018-06-08T10:04:47.306838847Z [2018-06-08 10:04:47,302: DEBUG/MainProcess] | Consumer: Starting Connection
2018-06-08T10:04:47.422910478Z [2018-06-08 10:04:47,421: INFO/Beat] beat: Starting...
2018-06-08T10:04:47.449327737Z [2018-06-08 10:04:47,448: DEBUG/Beat] Current schedule:
2018-06-08T10:04:47.449361345Z <Entry: purge_stdout_files awx.main.tasks.purge_old_stdout_files() <freq: 7.00 days>
2018-06-08T10:04:47.449367198Z <Entry: cluster_heartbeat awx.main.tasks.cluster_node_heartbeat() <freq: 1.00 minute>
2018-06-08T10:04:47.449370440Z <Entry: isolated_heartbeat awx.main.tasks.awx_isolated_heartbeat() <freq: 10.00 minutes>
2018-06-08T10:04:47.449374486Z <Entry: task_manager awx.main.scheduler.tasks.run_task_manager() <freq: 20.00 seconds>
2018-06-08T10:04:47.449377859Z <Entry: tower_scheduler awx.main.tasks.awx_periodic_scheduler() <freq: 30.00 seconds>
2018-06-08T10:04:47.449381280Z <Entry: celery.backend_cleanup celery.backend_cleanup() <crontab: 0 4 * * * (m/h/d/dM/MY)>
2018-06-08T10:04:47.449384529Z <Entry: admin_checks awx.main.tasks.run_administrative_checks() <freq: 30.00 days>
2018-06-08T10:04:47.449387621Z [2018-06-08 10:04:47,448: DEBUG/Beat] beat: Ticking with max interval->1.00 minute
2018-06-08T10:05:01.470460249Z RESULT 2
2018-06-08T10:05:01.470534770Z OKREADY
2018-06-08T10:06:01.544773272Z No previous hash foundRESULT 2
2018-06-08T10:06:01.544830978Z OKREADY
2018-06-08T10:06:31.402713141Z Traceback (most recent call last):
2018-06-08T10:06:31.402843306Z   File "/usr/bin/awx-manage", line 9, in <module>
2018-06-08T10:06:31.408065416Z     load_entry_point('awx==1.0.6.15', 'console_scripts', 'awx-manage')()
2018-06-08T10:06:31.408110795Z   File "/usr/lib/python2.7/site-packages/awx/__init__.py", line 109, in manage
2018-06-08T10:06:31.408159022Z     execute_from_command_line(sys.argv)
2018-06-08T10:06:31.408168228Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
2018-06-08T10:06:31.408172845Z     utility.execute()
2018-06-08T10:06:31.408176544Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
2018-06-08T10:06:31.408180465Z     self.fetch_command(subcommand).run_from_argv(self.argv)
2018-06-08T10:06:31.408184055Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
2018-06-08T10:06:31.408187684Z     self.execute(*args, **cmd_options)
2018-06-08T10:06:31.408191115Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
2018-06-08T10:06:31.408194452Z     output = self.handle(*args, **options)
2018-06-08T10:06:31.408197882Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/channels/management/commands/runworker.py", line 83, in handle
2018-06-08T10:06:31.408213810Z     worker.run()
2018-06-08T10:06:31.408217099Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/channels/worker.py", line 87, in run
2018-06-08T10:06:31.408220471Z     channel, content = self.channel_layer.receive_many(channels, block=True)
2018-06-08T10:06:31.408224243Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/asgiref/base_layer.py", line 43, in receive_many
2018-06-08T10:06:31.408227817Z     return self.receive(channels, block)
2018-06-08T10:06:31.408231170Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/asgi_amqp/core.py", line 102, in receive
2018-06-08T10:06:31.408234628Z     self._init_thread()
2018-06-08T10:06:31.408237867Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/asgi_amqp/core.py", line 63, in _init_thread
2018-06-08T10:06:31.408241169Z     self.tdata.connection.default_channel.basic_qos(0, 1, False)
2018-06-08T10:06:31.408244354Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 771, in default_channel
2018-06-08T10:06:31.408247691Z     self.connection
2018-06-08T10:06:31.408250880Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 756, in connection
2018-06-08T10:06:31.408254177Z     self._connection = self._establish_connection()
2018-06-08T10:06:31.408294371Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 711, in _establish_connection
2018-06-08T10:06:31.408298902Z     conn = self.transport.establish_connection()
2018-06-08T10:06:31.408301941Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
2018-06-08T10:06:31.408305014Z     conn = self.Connection(**opts)
2018-06-08T10:06:31.408308611Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 171, in __init__
2018-06-08T10:06:31.408311634Z     (10, 10),  # start
2018-06-08T10:06:31.408314544Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/abstract_channel.py", line 67, in wait
2018-06-08T10:06:31.408317559Z     self.channel_id, allowed_methods, timeout)
2018-06-08T10:06:31.408320385Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 241, in _wait_method
2018-06-08T10:06:31.408323427Z     channel, method_sig, args, content = read_timeout(timeout)
2018-06-08T10:06:31.408326439Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 330, in read_timeout
2018-06-08T10:06:31.408329455Z     return self.method_reader.read_method()
2018-06-08T10:06:31.408332286Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
2018-06-08T10:06:31.408335316Z     raise m
2018-06-08T10:06:31.408338257Z socket.error: [Errno 104] Connection reset by peer
2018-06-08T10:06:31.609201999Z 2018-06-08 10:06:31,608 INFO exited: channels-worker (exit status 1; not expected)
2018-06-08T10:06:32.613337258Z 2018-06-08 10:06:32,612 INFO spawned: 'channels-worker' with pid 230
2018-06-08T10:06:33.065300661Z [2018-06-08 10:06:33,064: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq:5672/awx: [Errno 104] Connection reset by peer.
2018-06-08T10:06:33.065359309Z Trying again in 2.00 seconds...
2018-06-08T10:06:33.065365639Z 
2018-06-08T10:06:33.192730312Z [2018-06-08 10:06:33,192: ERROR/Beat] beat: Connection error: [Errno 104] Connection reset by peer. Trying again in 2.0 seconds...
2018-06-08T10:06:34.194237874Z 2018-06-08 10:06:34,193 INFO success: channels-worker entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-06-08T10:06:34.978216775Z 2018-06-08 10:06:34,977 - INFO - runworker - Using single-threaded worker.
2018-06-08T10:06:34.982521834Z 2018-06-08 10:06:34,978 - INFO - runworker - Running worker against channel layer default (asgi_amqp.core.AMQPChannelLayer)
2018-06-08T10:06:34.982546477Z 2018-06-08 10:06:34,979 - INFO - worker - Listening on channels websocket.connect, websocket.disconnect, websocket.receive
2018-06-08T10:07:01.011688942Z RESULT 2
2018-06-08T10:07:01.011744823Z OKREADY
2018-06-08T10:08:01.089765113Z RESULT 2
2018-06-08T10:08:01.089842888Z OKREADY
2018-06-08T10:08:19.692101223Z Traceback (most recent call last):
2018-06-08T10:08:19.692210203Z   File "/usr/bin/awx-manage", line 9, in <module>
2018-06-08T10:08:19.695679482Z     load_entry_point('awx==1.0.6.15', 'console_scripts', 'awx-manage')()
2018-06-08T10:08:19.695700053Z   File "/usr/lib/python2.7/site-packages/awx/__init__.py", line 109, in manage
2018-06-08T10:08:19.695705168Z     execute_from_command_line(sys.argv)
2018-06-08T10:08:19.695708361Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
2018-06-08T10:08:19.695711830Z     utility.execute()
2018-06-08T10:08:19.695714835Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
2018-06-08T10:08:19.695718395Z     self.fetch_command(subcommand).run_from_argv(self.argv)
2018-06-08T10:08:19.695721336Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
2018-06-08T10:08:19.695736240Z     self.execute(*args, **cmd_options)
2018-06-08T10:08:19.695739358Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
2018-06-08T10:08:19.695742688Z     output = self.handle(*args, **options)
2018-06-08T10:08:19.695745744Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/channels/management/commands/runworker.py", line 83, in handle
2018-06-08T10:08:19.695748989Z     worker.run()
2018-06-08T10:08:19.695751939Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/channels/worker.py", line 87, in run
2018-06-08T10:08:19.695755355Z     channel, content = self.channel_layer.receive_many(channels, block=True)
2018-06-08T10:08:19.695758251Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/asgiref/base_layer.py", line 43, in receive_many
2018-06-08T10:08:19.695762484Z     return self.receive(channels, block)
2018-06-08T10:08:19.695767315Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/asgi_amqp/core.py", line 102, in receive
2018-06-08T10:08:19.695772296Z     self._init_thread()
2018-06-08T10:08:19.695778430Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/asgi_amqp/core.py", line 63, in _init_thread
2018-06-08T10:08:19.695784368Z     self.tdata.connection.default_channel.basic_qos(0, 1, False)
2018-06-08T10:08:19.695789053Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 771, in default_channel
2018-06-08T10:08:19.695794259Z     self.connection
2018-06-08T10:08:19.695798734Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 756, in connection
2018-06-08T10:08:19.695803632Z     self._connection = self._establish_connection()
2018-06-08T10:08:19.695812408Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/connection.py", line 711, in _establish_connection
2018-06-08T10:08:19.695837956Z     conn = self.transport.establish_connection()
2018-06-08T10:08:19.695841455Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
2018-06-08T10:08:19.695844560Z     conn = self.Connection(**opts)
2018-06-08T10:08:19.695847306Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 171, in __init__
2018-06-08T10:08:19.695850286Z     (10, 10),  # start
2018-06-08T10:08:19.695852994Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/abstract_channel.py", line 67, in wait
2018-06-08T10:08:19.695855936Z     self.channel_id, allowed_methods, timeout)
2018-06-08T10:08:19.695858698Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 241, in _wait_method
2018-06-08T10:08:19.695861740Z     channel, method_sig, args, content = read_timeout(timeout)
2018-06-08T10:08:19.695864511Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/connection.py", line 330, in read_timeout
2018-06-08T10:08:19.695867444Z     return self.method_reader.read_method()
2018-06-08T10:08:19.695870181Z   File "/var/lib/awx/venv/awx/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
2018-06-08T10:08:19.695873222Z     raise m
2018-06-08T10:08:19.695875945Z socket.error: [Errno 104] Connection reset by peer
2018-06-08T10:08:19.817022905Z [2018-06-08 10:08:19,816: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@rabbitmq:5672/awx: [Errno 104] Connection reset by peer.
2018-06-08T10:08:19.817088636Z Trying again in 4.00 seconds...
2018-06-08T10:08:19.817094646Z 
2018-06-08T10:08:19.876568040Z 2018-06-08 10:08:19,876 INFO exited: channels-worker (exit status 1; not expected)
2018-06-08T10:08:20.880076422Z 2018-06-08 10:08:20,879 INFO spawned: 'channels-worker' with pid 241
2018-06-08T10:08:21.882123169Z 2018-06-08 10:08:21,881 INFO success: channels-worker entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2018-06-08T10:08:22.888318987Z [2018-06-08 10:08:22,887: ERROR/Beat] beat: Connection error: [Errno 104] Connection reset by peer. Trying again in 4.0 seconds...
2018-06-08T10:08:23.456245395Z 2018-06-08 10:08:23,455 - INFO - runworker - Using single-threaded worker.
2018-06-08T10:08:23.459792862Z 2018-06-08 10:08:23,456 - INFO - runworker - Running worker against channel layer default (asgi_amqp.core.AMQPChannelLayer)
2018-06-08T10:08:23.459847169Z 2018-06-08 10:08:23,456 - INFO - worker - Listening on channels websocket.connect, websocket.disconnect, websocket.receive
2018-06-08T10:09:01.506534481Z RESULT 2
2018-06-08T10:09:01.506587366Z OKREADY


# Fixed code
def run_pexpect(
    args,
    cwd,
    env,
    logfile,
    cancelled_callback=None,
    expect_passwords={},
    extra_update_fields=None,
    idle_timeout=None,
    job_timeout=0,
    pexpect_timeout=5,
    proot_cmd="bwrap",
):
    """
    Run the given command using pexpect to capture output and provide
    passwords when requested.

    :param args:                a list of `subprocess.call`-style arguments
                                representing a subprocess e.g., ['ls', '-la']
    :param cwd:                 the directory in which the subprocess should
                                run
    :param env:                 a dict containing environment variables for the
                                subprocess, ala `os.environ`
    :param logfile:             a file-like object for capturing stdout
    :param cancelled_callback:  a callable - which returns `True` or `False`
                                - signifying if the job has been prematurely
                                  cancelled
    :param expect_passwords:    a dict of regular expression password prompts
                                to input values, i.e., {r'Password:\s*?$':
                                'some_password'}
    :param extra_update_fields: a dict used to specify DB fields which should
                                be updated on the underlying model
                                object after execution completes
    :param idle_timeout         a timeout (in seconds); if new output is not
                                sent to stdout in this interval, the process
                                will be terminated
    :param job_timeout          a timeout (in seconds); if the total job runtime
                                exceeds this, the process will be killed
    :param pexpect_timeout      a timeout (in seconds) to wait on
                                `pexpect.spawn().expect()` calls
    :param proot_cmd            the command used to isolate processes, `bwrap`

    Returns a tuple (status, return_code) i.e., `('successful', 0)`
    """
    expect_passwords[pexpect.TIMEOUT] = None
    expect_passwords[pexpect.EOF] = None

    if not isinstance(expect_passwords, collections.OrderedDict):
        # We iterate over `expect_passwords.keys()` and
        # `expect_passwords.values()` separately to map matched inputs to
        # patterns and choose the proper string to send to the subprocess;
        # enforce usage of an OrderedDict so that the ordering of elements in
        # `keys()` matches `values()`.
        expect_passwords = collections.OrderedDict(expect_passwords)
    password_patterns = expect_passwords.keys()
    password_values = expect_passwords.values()

    child = pexpect.spawn(
        args[0],
        args[1:],
        cwd=cwd,
        env=env,
        ignore_sighup=True,
        encoding="utf-8",
        echo=False,
        use_poll=True,
    )
    child.logfile_read = logfile
    canceled = False
    timed_out = False
    errored = False
    last_stdout_update = time.time()

    job_start = time.time()
    while child.isalive():
        result_id = child.expect(
            password_patterns, timeout=pexpect_timeout, searchwindowsize=100
        )
        password = password_values[result_id]
        if password is not None:
            child.sendline(password)
            last_stdout_update = time.time()
        if cancelled_callback:
            try:
                canceled = cancelled_callback()
            except Exception:
                logger.exception(
                    "Could not check cancel callback - canceling immediately"
                )
                if isinstance(extra_update_fields, dict):
                    extra_update_fields["job_explanation"] = (
                        "System error during job execution, check system logs"
                    )
                errored = True
        else:
            canceled = False
        if (
            not canceled
            and job_timeout != 0
            and (time.time() - job_start) > job_timeout
        ):
            timed_out = True
            if isinstance(extra_update_fields, dict):
                extra_update_fields["job_explanation"] = "Job terminated due to timeout"
        if canceled or timed_out or errored:
            handle_termination(child.pid, child.args, proot_cmd, is_cancel=canceled)
        if idle_timeout and (time.time() - last_stdout_update) > idle_timeout:
            child.close(True)
            canceled = True
    if errored:
        return "error", child.exitstatus
    elif canceled:
        return "canceled", child.exitstatus
    elif child.exitstatus == 0 and not timed_out:
        return "successful", child.exitstatus
    else:
        return "failed", child.exitstatus