使用带有docker-compose.yml的docker_service模块时,“TypeError:不能在类字节对象上使用字符串模式”

时间:2017-07-29 21:56:09

标签: docker ansible docker-compose

我有以下docker-compose.yml

version: "3"
services:

  container0:
    image: myimage
    build:
      context: .
    ports:
      - "10000:22"

  container1:
    image: myimage
    build:
      context: .
    ports:
      - "10001:22"

  container2:
    image: myimage
    build:
      context: .
    ports:
      - "10002:22"

以及我的剧本中的以下任务:

    - name: setting up containers
      docker_service:
        project_src: .
        files:
          - docker-compose.yml
        state: present

docker-compose.yml似乎正确,直接使用docker-compose up消费时没有错误。

但是在运行我的剧本时,我得到以下内容:

$ ansible-playbook -e 'ansible_python_interpreter=/usr/bin/python3' playbook.yml

PLAY [set up containers] **********************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************
ok: [localhost]

[...]

TASK [setting up containers] ***********************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Creating containers_container0_1 ... \r\nCreating containers_container2_1 ... \r\nCreating containers_container1_1 ... \r\n\u001b[1A\u001b[2K\rCreating containers_container0_1 ... \u001b[32mdone\u001b[0m\r\u001b[1B\u001b[1A\u001b[2K\rCreating containers_container2_1 ... \u001b[32mdone\u001b[0m\r\u001b[1B\u001b[1A\u001b[2K\rCreating containers_container1_1 ... \u001b[32mdone\u001b[0m\r\u001b[1BTraceback (most recent call last):\n  File \"/tmp/ansible_hvp0_qgr/ansible_module_docker_service.py\", line 1016, in <module>\n    main()\n  File \"/tmp/ansible_hvp0_qgr/ansible_module_docker_service.py\", line 1011, in main\n    result = ContainerManager(client).exec_module()\n  File \"/tmp/ansible_hvp0_qgr/ansible_module_docker_service.py\", line 608, in exec_module\n    result = self.cmd_up()\n  File \"/tmp/ansible_hvp0_qgr/ansible_module_docker_service.py\", line 703, in cmd_up\n    get_stdout(fd_name)\n  File \"/tmp/ansible_hvp0_qgr/ansible_module_docker_service.py\", line 512, in get_stdout\n    new_line = re.sub(r'\\x1b\\[.+m', '', line.encode('ascii'))\n  File \"/usr/lib/python3.6/re.py\", line 191, in sub\n    return _compile(pattern, flags).sub(repl, string, count)\nTypeError: cannot use a string pattern on a bytes-like object\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
        to retry, use: --limit @/home/vmonteco/Code/Perso/Ansible/containers/playbook.retry

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

什么可能导致此错误?

在运行此命令后,仍然可以成功创建和启动容器。

1 个答案:

答案 0 :(得分:0)

错误摘录:

  

...文件\&#34; /usr/lib/python3.6/re.py \&#34;,第191行......

Python 3? Ansible尚未与Python 3完全兼容(截至编写本答案时)。