# Buggy code
def _accept_or_ignore_job_kwargs(self, **kwargs):
    exclude_errors = kwargs.pop("_exclude_errors", [])
    prompted_data = {}
    rejected_data = {}
    accepted_vars, rejected_vars, errors_dict = self.accept_or_ignore_variables(
        kwargs.get("extra_vars", {}),
        _exclude_errors=exclude_errors,
        extra_passwords=kwargs.get("survey_passwords", {}),
    )
    if accepted_vars:
        prompted_data["extra_vars"] = accepted_vars
    if rejected_vars:
        rejected_data["extra_vars"] = rejected_vars

    # Handle all the other fields that follow the simple prompting rule
    for field_name, ask_field_name in self.get_ask_mapping().items():
        if (
            field_name not in kwargs
            or field_name == "extra_vars"
            or kwargs[field_name] is None
        ):
            continue

        new_value = kwargs[field_name]
        old_value = getattr(self, field_name)

        field = self._meta.get_field(field_name)
        if isinstance(field, models.ManyToManyField):
            old_value = set(old_value.all())
            if getattr(self, "_deprecated_credential_launch", False):
                # TODO: remove this code branch when support for `extra_credentials` goes away
                new_value = set(kwargs[field_name])
            else:
                new_value = set(kwargs[field_name]) - old_value
                if not new_value:
                    continue

        if new_value == old_value:
            # no-op case: Fields the same as template's value
            # counted as neither accepted or ignored
            continue
        elif getattr(self, ask_field_name):
            # accepted prompt
            prompted_data[field_name] = new_value
        else:
            # unprompted - template is not configured to accept field on launch
            rejected_data[field_name] = new_value
            # Not considered an error for manual launch, to support old
            # behavior of putting them in ignored_fields and launching anyway
            if "prompts" not in exclude_errors:
                errors_dict[field_name] = _(
                    "Field is not configured to prompt on launch."
                ).format(field_name=field_name)

    if "prompts" not in exclude_errors and self.passwords_needed_to_start:
        errors_dict["passwords_needed_to_start"] = _(
            "Saved launch configurations cannot provide passwords needed to start."
        )

    needed = self.resources_needed_to_start
    if needed:
        needed_errors = []
        for resource in needed:
            if resource in prompted_data:
                continue
            needed_errors.append(
                _("Job Template {} is missing or undefined.").format(resource)
            )
        if needed_errors:
            errors_dict["resources_needed_to_start"] = needed_errors

    return prompted_data, rejected_data, errors_dict


# Traceback (TypeError)
./awx_install.sh

HEAD is now at 2e98029 Merge pull request #2009 from cdvv7788/Issue/1506
Already up-to-date.

PLAY [Build and deploy AWX] *********************************************************************************************************************************

TASK [check_vars : include_tasks] ***************************************************************************************************************************
skipping: [localhost]

TASK [check_vars : include_tasks] ***************************************************************************************************************************
included: /<install dir>/installer/roles/check_vars/tasks/check_docker.yml for localhost

TASK [check_vars : postgres_data_dir should be defined] *****************************************************************************************************
ok: [localhost] => {
"changed": false,
"msg": "All assertions passed"
}

TASK [check_vars : host_port should be defined] *************************************************************************************************************
ok: [localhost] => {
"changed": false,
"msg": "All assertions passed"
}

TASK [image_build : Get Version from checkout if not provided] **********************************************************************************************
skipping: [localhost]

TASK [image_build : Set global version if not provided] *****************************************************************************************************
skipping: [localhost]

TASK [image_build : Verify awx-logos directory exists for official install] *********************************************************************************
skipping: [localhost]

TASK [image_build : Copy logos for inclusion in sdist] ******************************************************************************************************
skipping: [localhost]

TASK [image_build : Set sdist file name] ********************************************************************************************************************
skipping: [localhost]

TASK [image_build : AWX Distribution] ***********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stat distribution file] *****************************************************************************************************************
skipping: [localhost]

TASK [image_build : Clean distribution] *********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Build sdist builder image] **************************************************************************************************************
skipping: [localhost]

TASK [image_build : Build AWX distribution using container] *************************************************************************************************
skipping: [localhost]

TASK [image_build : Build AWX distribution locally] *********************************************************************************************************
skipping: [localhost]

TASK [image_build : Set docker build base path] *************************************************************************************************************
skipping: [localhost]

TASK [image_build : Set awx_web image name] *****************************************************************************************************************
skipping: [localhost]

TASK [image_build : Set awx_task image name] ****************************************************************************************************************
skipping: [localhost]

TASK [image_build : Ensure directory exists] ****************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage sdist] ****************************************************************************************************************************
skipping: [localhost]

TASK [image_build : Template web Dockerfile] ****************************************************************************************************************
skipping: [localhost]

TASK [image_build : Template task Dockerfile] ***************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage launch_awx] ***********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage launch_awx_task] ******************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage nginx.conf] ***********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage supervisor.conf] ******************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage supervisor_task.conf] *************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage settings.py] **********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage requirements] *********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage config watcher] *******************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage Makefile] *************************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage ansible repo] *********************************************************************************************************************
skipping: [localhost]

TASK [image_build : Stage ansible repo key] *****************************************************************************************************************
skipping: [localhost]

TASK [image_build : Build base web image] *******************************************************************************************************************
skipping: [localhost]

TASK [image_build : Build base task image] ******************************************************************************************************************
skipping: [localhost]

TASK [image_build : Tag task and web images as latest] ******************************************************************************************************
skipping: [localhost]

TASK [image_build : Clean docker base directory] ************************************************************************************************************
skipping: [localhost]

TASK [image_push : Authenticate with Docker registry if registry password given] ****************************************************************************
skipping: [localhost]

TASK [image_push : Remove web image] ************************************************************************************************************************
skipping: [localhost]

TASK [image_push : Remove task image] ***********************************************************************************************************************
skipping: [localhost]

TASK [image_push : Tag and push web image to registry] ******************************************************************************************************
skipping: [localhost]

TASK [image_push : Tag and push task image to registry] *****************************************************************************************************
skipping: [localhost]

TASK [image_push : Set full image path for Registry] ********************************************************************************************************
skipping: [localhost]

TASK [kubernetes : fail] ************************************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Set kubernetes base path] ****************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : include_tasks] ***************************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : include_tasks] ***************************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Use kubectl or oc] ***********************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Get Postgres Service Detail] *************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Template PostgreSQL Deployment] **********************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Deploy and Activate Postgres] ************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Deploy and Activate Postgres (Kubernetes)] ***********************************************************************************************
skipping: [localhost]

TASK [kubernetes : Set postgresql hostname to helm package service] *****************************************************************************************
skipping: [localhost]

TASK [kubernetes : Wait for Postgres to activate] ***********************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Ensure directory exists] *****************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Template Kubernetes AWX Config] **********************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Set task image name] *********************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Set web image name] **********************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Template Kubernetes AWX Deployment] ******************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Apply Configmap] *************************************************************************************************************************
skipping: [localhost]

TASK [kubernetes : Apply Deployment] ************************************************************************************************************************
skipping: [localhost]

TASK [local_docker : Export Docker web image if it isnt local and there isnt a registry defined] ************************************************************
skipping: [localhost]

TASK [local_docker : Export Docker task image if it isnt local and there isnt a registry defined] ***********************************************************
skipping: [localhost]

TASK [local_docker : Set docker base path] ******************************************************************************************************************
skipping: [localhost]

TASK [local_docker : Ensure directory exists] ***************************************************************************************************************
skipping: [localhost]

TASK [local_docker : Copy web image to docker execution] ****************************************************************************************************
skipping: [localhost]

TASK [local_docker : Copy task image to docker execution] ***************************************************************************************************
skipping: [localhost]

TASK [local_docker : Load web image] ************************************************************************************************************************
skipping: [localhost]

TASK [local_docker : Load task image] ***********************************************************************************************************************
skipping: [localhost]

TASK [local_docker : Set full image path for local install] *************************************************************************************************
skipping: [localhost]

TASK [local_docker : Set DockerHub Image Paths] *************************************************************************************************************
ok: [localhost]

TASK [local_docker : Activate postgres container] ***********************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: create_host_config() got an unexpected keyword argument 'init'
fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_f2TUMm/ansible_module_docker_container.py\", line 2081, in <module>\n    main()\n  File \"/tmp/ansible_f2TUMm/ansible_module_docker_container.py\", line 2076, in main\n    cm = ContainerManager(client)\n  File \"/tmp/ansible_f2TUMm/ansible_module_docker_container.py\", line 1703, in __init__\n    self.present(state)\n  File \"/tmp/ansible_f2TUMm/ansible_module_docker_container.py\", line 1723, in present\n    new_container = self.container_create(self.parameters.image, self.parameters.create_parameters)\n  File \"/tmp/ansible_f2TUMm/ansible_module_docker_container.py\", line 825, in create_parameters\n    host_config=self._host_config(),\n  File \"/tmp/ansible_f2TUMm/ansible_module_docker_container.py\", line 931, in _host_config\n    return self.client.create_host_config(**params)\n  File \"/usr/local/lib/python2.7/dist-packages/docker/api/container.py\", line 157, in create_host_config\n    return utils.create_host_config(*args, **kwargs)\nTypeError: create_host_config() got an unexpected keyword argument 'init'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 1}
to retry, use: --limit @/<install dir>/installer/install.retry

PLAY RECAP **************************************************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=1

# Fixed code
def _accept_or_ignore_job_kwargs(self, **kwargs):
    exclude_errors = kwargs.pop("_exclude_errors", [])
    prompted_data = {}
    rejected_data = {}
    accepted_vars, rejected_vars, errors_dict = self.accept_or_ignore_variables(
        kwargs.get("extra_vars", {}),
        _exclude_errors=exclude_errors,
        extra_passwords=kwargs.get("survey_passwords", {}),
    )
    if accepted_vars:
        prompted_data["extra_vars"] = accepted_vars
    if rejected_vars:
        rejected_data["extra_vars"] = rejected_vars

    # Handle all the other fields that follow the simple prompting rule
    for field_name, ask_field_name in self.get_ask_mapping().items():
        if (
            field_name not in kwargs
            or field_name == "extra_vars"
            or kwargs[field_name] is None
        ):
            continue

        new_value = kwargs[field_name]
        old_value = getattr(self, field_name)

        field = self._meta.get_field(field_name)
        if isinstance(field, models.ManyToManyField):
            old_value = set(old_value.all())
            if getattr(self, "_deprecated_credential_launch", False):
                # TODO: remove this code branch when support for `extra_credentials` goes away
                new_value = set(kwargs[field_name])
            else:
                new_value = set(kwargs[field_name]) - old_value
                if not new_value:
                    continue

        if new_value == old_value:
            # no-op case: Fields the same as template's value
            # counted as neither accepted or ignored
            continue
        elif getattr(self, ask_field_name):
            # accepted prompt
            prompted_data[field_name] = new_value
        else:
            # unprompted - template is not configured to accept field on launch
            rejected_data[field_name] = new_value
            # Not considered an error for manual launch, to support old
            # behavior of putting them in ignored_fields and launching anyway
            if "prompts" not in exclude_errors:
                errors_dict[field_name] = _(
                    "Field is not configured to prompt on launch."
                ).format(field_name=field_name)

    if (
        "prompts" not in exclude_errors
        and (not getattr(self, "ask_credential_on_launch", False))
        and self.passwords_needed_to_start
    ):
        errors_dict["passwords_needed_to_start"] = _(
            "Saved launch configurations cannot provide passwords needed to start."
        )

    needed = self.resources_needed_to_start
    if needed:
        needed_errors = []
        for resource in needed:
            if resource in prompted_data:
                continue
            needed_errors.append(
                _("Job Template {} is missing or undefined.").format(resource)
            )
        if needed_errors:
            errors_dict["resources_needed_to_start"] = needed_errors

    return prompted_data, rejected_data, errors_dict