异步任务未返回有效的JSON

时间:2016-06-05 00:16:29

标签: ansible ansible-playbook ansible-2.x

不可思议的版本
ansible --version
ansible 2.0.2.0
  config file =
  configured module search path = Default w/o overrides
操作系统/环境
MacOS 10.9
摘要

我想启动shell命令以异步方式构建docker镜像,构建成功但发生此错误:

    fatal: [192.168.0.1]: FAILED! => {"changed": false, "failed": true, "msg": "The async task did not return valid JSON: No JSON object could be decoded"}
重现步骤
<!---
For bugs, show exactly how to reproduce the problem.
For new features, show how the feature would be used.
-->

我手动执行了python片段ansible执行:

/root/.ansible/tmp/ansible-tmp-1465081459.8-258691745536723/command
/root/.ansible/tmp/ansible-tmp-1465081459.8-258691745536723/arguments

结果是

{
    "changed": true,
    "end": "2016-06-05 07:12:38.323820",
    "stdout": "Sending build context to Docker daemon  12.8 kB\r\r
    Step 1 : FROM centos:6.6
     ---> 87dd25f5ba5c
    Step 2 : RUN yum groupinstall -y development
     ---> Using cache
     ---> dc1b778350d5
    Step 3 : RUN yum install -y vim bzip2-devel  hostname tar zlib-dev
     ---> Using cache
     ---> d4538794340e
    Step 4 : RUN curl https://bootstrap.pypa.io/get-pip.py | python -
     ---> Using cache
     ---> cd3cd13b11db
    Step 5 : RUN pip install envtpl
     ---> Using cache
     ---> 574514eb6d91
    Step 6 : WORKDIR /tmp
     ---> Using cache
     ---> 3750674900e6
    Step 7 : ENV SCALA_VERSION 2.11
     ---> Using cache
     ---> 8316460b0264
    Step 8 : ENV KAFKA_VERSION 0.9.0.1
     ---> Using cache
     ---> aa8f9cf12288
    Step 9 : ENV KAFKA_HOME /usr/share/kafka_\"$SCALA_VERSION\"-\"$KAFKA_VERSION\"
     ---> Using cache
     ---> 38c1243614ac
    Step 10 : RUN yum install -y tar libcurl libcurl-devel rrdtool rrdtool-devel perl-devel libgcrypt-devel gcc make gcc-c++ yajl-devel libxml2-devel libxml-2.0 java-1.7.0-openjdk java-1.7.0-openjdk-devel
     ---> Using cache
     ---> 8350d7ba311a
    Step 11 : RUN curl -L -O http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/\"$KAFKA_VERSION\"/kafka_\"$SCALA_VERSION\"-\"$KAFKA_VERSION\".tgz && tar xfz kafka_\"$SCALA_VERSION\"-\"$KAFKA_VERSION\".tgz -C /usr/share/
     ---> Using cache
     ---> 485916280855
    Step 12 : RUN mkdir -p /usr/local/bin/
     ---> Using cache
     ---> 2a3427511ef0
    Step 13 : ADD start-kafka.sh /usr/local/bin/start-kafka.sh
     ---> Using cache
     ---> 6cd1ae0c2abc
    Step 14 : RUN chmod +x  /usr/local/bin/start-kafka.sh
     ---> Using cache
     ---> 4ba3e949839e
    Step 15 : ADD zookeeper.properties.j2 \"$KAFKA_HOME\"/config/
     ---> Using cache
     ---> db8bfa4cce0d
    Step 16 : ADD server.properties.j2 \"$KAFKA_HOME\"/config/
     ---> Using cache
     ---> b2d93fd06892
    Step 17 : EXPOSE 2181 9092
     ---> Using cache
     ---> 25f1e2136c2c
    Step 18 : RUN mv /etc/localtime /etc/localtime.bak
     ---> Using cache
     ---> 1cf4fc533f3a
    Step 19 : RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
     ---> Using cache
     ---> b6bae747bc32
    Step 20 : CMD /usr/local/bin/start-kafka.sh
     ---> Using cache
     ---> 9920101ececa
    Successfully built 9920101ececa",
    "cmd": "docker build -t elk/kafka /tmp/dockerfile/kafka",
    "rc": 0,
    "start": "2016-06-05 07:12:38.253244",
    "stderr": "",
    "delta": "0:00:00.070576",
        "invocation": {
        "module_args": {"warn": true,
            "executable": null,
            "chdir": null,
            "_raw_params": "docker build -t elk/kafka /tmp/dockerfile/kafka",
            "removes": null,
            "creates": null,
            "_uses_shell": true
        }
    },
    "warnings": []
}

我执行的任务是

- name: build or check kafka docker image
  shell: docker build -t {{ image_name }} /tmp/dockerfile/kafka
  async: 2400                                     # wait seconds
  poll: 5                                        # poll wait seconds

1 个答案:

答案 0 :(得分:2)

我终于努力解决这个问题了。我添加了代码以在文件executor/task_executor.py下的第445行打印结果:

return dict(failed=True, msg=u"The async task did not return valid JSON: error:%s result:%s" % (to_unicode(e), result))

然后我发现了一些无效的json文本:/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\\r\\nlink的帮助下修复了这个语言环境问题后,这个问题就消失了。