Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playbook ansible with vagrant raises error because of task docker_service. #23607

Closed
JorisLA opened this issue Apr 14, 2017 · 22 comments
Closed
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.

Comments

@JorisLA
Copy link

JorisLA commented Apr 14, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Task docker_service

ANSIBLE VERSION
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides

CONFIGURATION

No changes

OS / ENVIRONMENT

Running Ansible from ubuntu 16.04 LTS.
Managing Ansible from a VM (debian 8 jessie)

SUMMARY

Using docker_service to do a 'docker-compose up'. At the end a FAILED message appears but the containers runs properly in the VM.

STEPS TO REPRODUCE
---
- hosts: localhost
  become: yes
    - docker_service:
        project_src: /vagrant
        state: present

This is a part of my Vagrantfile

 config.vm.box = "debian/jessie64"

 config.vm.network "forwarded_port", guest: 8080, host: 8080

 config.vm.provision "ansible" do |ansible|
      ansible.groups = {
        'localhost' => ['default']
      }
      ansible.playbook = "bootstrap.yml"
 end

This is my docker-compose.yml

version: '2'

services:
  backend:
    build:
      context: backend/
      args:
        TAIGA_SECRET_KEY: ${TAIGA_SECRET_KEY}
        TAIGA_HOSTNAME: ${TAIGA_HOSTNAME}
        # To use an external SMTP for emails, fill in these values:
        TAIGA_ENABLE_EMAIL: ${TAIGA_ENABLE_EMAIL}
        TAIGA_EMAIL_FROM: ${TAIGA_EMAIL_FROM}
        TAIGA_EMAIL_USE_TLS: ${TAIGA_EMAIL_USE_TLS}
        TAIGA_EMAIL_HOST: ${TAIGA_EMAIL_HOST}
        TAIGA_EMAIL_PORT: ${TAIGA_EMAIL_PORT}
        TAIGA_EMAIL_USER: ${TAIGA_EMAIL_USER}
        TAIGA_EMAIL_PASS: ${TAIGA_EMAIL_PASS}
        RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
        RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
        RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_DEFAULT_VHOST}
    volumes:
      - ./media:/usr/src/taiga-back/media
    environment:
      # Database settings
      # To use an external database, simply update these and remove the postgres
      # service from this docker-compose.yml file
      TAIGA_DB_NAME: ${TAIGA_DB_NAME}
      TAIGA_DB_HOST: ${TAIGA_DB_HOST}
      TAIGA_DB_USER: ${TAIGA_DB_USER}
      TAIGA_DB_PASSWORD: ${TAIGA_DB_PASSWORD}
      TAIGA_SLEEP: 15 # when the db comes up from docker, it is usually too quick
      RABBIT_PORT: 5672
      REDIS_PORT: 6379

  frontend:
    build: frontend/
    ports:
      - "80:80"
    environment:
      # Your hostname (REQUIRED)
      TAIGA_HOSTNAME: ${TAIGA_HOSTNAME}
    depends_on:
      - backend

  rabbitmq:
    image: rabbitmq:latest
    hostname: rabbitmq
    command: rabbitmq-server
    ports:
      - '5672:5672'
      - '15672:15672'
    environment:
      # https://www.rabbitmq.com/clustering.html#erlang-cookie
      #- RABBITMQ_ERLANG_COOKIE='secret_cookie_here'
      RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
      RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
      RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_DEFAULT_VHOST}
      # http://www.rabbitmq.com/configure.html#config-items
      # - RABBITMQ_HIPE_COMPILE=1

  redis:
    image: redis:latest
    command: redis-server
    ports:
      - '6379:6379'

  events:
    hostname: events
    build: events/
    environment:
      TAIGA_SECRET_KEY: ${TAIGA_SECRET_KEY}
      RABBITMQ_DEFAULT_USER: ${RABBITMQ_DEFAULT_USER}
      RABBITMQ_DEFAULT_PASS: ${RABBITMQ_DEFAULT_PASS}
      RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_DEFAULT_VHOST}
    command: ['coffee','index.coffee']
EXPECTED RESULTS
PLAY [localhost] ***************************************************************

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

TASK [docker_service] **************************************************
ok: [default]
ACTUAL RESULTS
TASK [docker_service] **********************************************************
fatal: [default]: FAILED! => {
"changed": false, "failed": true,
"module_stderr": "Shared connection to 127.0.0.1 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n
File \"/tmp/ansible_yvaFKx/ansible_module_docker_service.py\", line 1016,
in <module>\r\n    main()\r\n  File \"/tmp/ansible_yvaFKx/ansible_module_docker_service.py\",
line 1011, in main\r\n
result = ContainerManager(client).exec_module()\r\n
File \"/tmp/ansible_yvaFKx/ansible_module_docker_service.py\",
line 608, in exec_module\r\n    result = self.cmd_up()\r\n
File \"/tmp/ansible_yvaFKx/ansible_module_docker_service.py\",
line 703, in cmd_up\r\n    get_stdout(fd_name)\r\n
File \"/tmp/ansible_yvaFKx/ansible_module_docker_service.py\",
line 512, in get_stdout\r\n    new_line = re.sub(r'\\x1b\\[.+m', '',
line.encode('ascii'))\r\n
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
 ordinal not in range(128)\r\n",
 "msg": "MODULE FAILURE", "rc": 0}
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report needs_triage Needs a first human triage before being processed. labels Apr 14, 2017
@snowsky
Copy link
Contributor

snowsky commented Apr 14, 2017

What is the output on your terminal, echo $LANG?

@surudoiryu
Copy link

surudoiryu commented Apr 14, 2017

Got the same error also with docker_service in my project:

Ansible task:

- name: Run Docker-Compose from project
  docker_service:
    build: yes
    project_name: project
    project_src: /var/www

Docker-compose:

version: '3'
services:
  web:
    build:
      context: .
      dockerfile: web.docker
    volumes:
      - .:/var/www
    ports:
      - 80:80
    links:
      - app
  app:
    build:
      context: .
      dockerfile: app.docker
    volumes:
      - .:/var/www
    links:
      - db
      - cache
    environment:
      - DB_PORT=3306
      - DB_HOST=db
      - REDIS_PORT=6379
      - REDIS_HOST=cache
  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=secret
      - MYSQL_DATABASE=project
    ports:
      - 3306:3306
  cache:
    image: redis:latest
    ports:
      - 6379:6379

Error:

Traceback (most recent call last):\r\n  
File \"/tmp/ansible_p8pdzrpz/ansible_module_docker_service.py\", line 1016, in <module>\r\n    
main()\r\n  
File \"/tmp/ansible_p8pdzrpz/ansible_module_docker_service.py\", line 1011, in main\r\n    
result = ContainerManager(client).exec_module()\r\n  
File \"/tmp/ansible_p8pdzrpz/ansible_module_docker_service.py\", line 608, in exec_module\r\n    
result = self.cmd_up()\r\n  
File \"/tmp/ansible_p8pdzrpz/ansible_module_docker_service.py\", line 703, in cmd_up\r\n 
get_stdout(fd_name)\r\n  
File \"/tmp/ansible_p8pdzrpz/ansible_module_docker_service.py\", line 512, in get_stdout\r\n    
new_line = re.sub(r'\\x1b\\[.+m', '', line.encode('ascii'))\r\n  
File \"/usr/lib/python3.5/re.py\", line 182, in sub\r\n    
return _compile(pattern, flags).sub(repl, string, count)\r\n
TypeError: cannot use a string pattern on a bytes-like object\r\n
", "msg": "MODULE FAILURE", "rc": 0}

@alikins
Copy link
Contributor

alikins commented Apr 17, 2017

@surudoiryu

Got the same error also with docker_service in my project:

Got the same error as what? #23607 (comment) is not the same as the error in #23607 (comment)

#23607 (comment) looks to be a python3 compatibility error and likely should be a different issue.

@alikins alikins added docker module This issue/PR relates to a module. and removed needs_triage Needs a first human triage before being processed. labels Apr 17, 2017
@JorisLA
Copy link
Author

JorisLA commented Apr 18, 2017

@snowsky
=> fr_FR.UTF-8

@surudoiryu
Copy link

@alikins
Aah i see now, i wasn't watching the last part -_-" my bad, it just looked a lot like this problem.

@snowsky
Copy link
Contributor

snowsky commented Apr 18, 2017

Will replacing acsii with utf-8 fix this issue?

@snowsky
Copy link
Contributor

snowsky commented Apr 18, 2017

Try this command before ansible-playbook:

export PYTHONIOENCODING=utf-8

@JorisLA
Copy link
Author

JorisLA commented Apr 18, 2017

It doesn't fix it, same error.

@snowsky
Copy link
Contributor

snowsky commented Apr 18, 2017

I cannot reproduce. Could you please try 6ec4f18?

@sivel
Copy link
Member

sivel commented Apr 18, 2017

I can produce this. I believe the appropriate fix is actually the following:

diff --git a/lib/ansible/modules/cloud/docker/docker_service.py b/lib/ansible/modules/cloud/docker/docker_service.py
index 785e8c9..34fab3b 100644
--- a/lib/ansible/modules/cloud/docker/docker_service.py
+++ b/lib/ansible/modules/cloud/docker/docker_service.py
@@ -480,6 +480,7 @@ except ImportError as exc:
     DEFAULT_TIMEOUT = 10
 
 from ansible.module_utils.docker_common import *
+from ansible.module_utils._text import to_native
 from contextlib import contextmanager
 
 
@@ -509,11 +510,11 @@ def get_stdout(path_name):
     with open(path_name, 'r') as fd:
         for line in fd:
             # strip terminal format/color chars
-            new_line = re.sub(r'\x1b\[.+m', '', line.encode('ascii'))
+            new_line = re.sub(r'\x1b\[.+m', '', to_native(line))
             full_stdout += new_line
             if new_line.strip():
                 # Assuming last line contains the error message
-                last_line = new_line.strip().encode('utf-8')
+                last_line = to_native(new_line.strip())
     fd.close()
     os.remove(path_name)
     return full_stdout, last_line

This error occurs when the "build" phase, outputs non-ascii characters. Which would involve that one of the services from the docker-compose.yml or definitions specify a "build" that would produce a non-ascii character.

snowsky added a commit to snowsky/ansible-1 that referenced this issue Apr 18, 2017
@snowsky
Copy link
Contributor

snowsky commented Apr 18, 2017

Thanks @sivel, the PR was just updated.

@JorisLA
Copy link
Author

JorisLA commented Apr 18, 2017

Thank you guys !

@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot
Copy link
Contributor

ansibot commented Nov 20, 2017

@ansibot ansibot added cloud support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 20, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@Akasurde
Copy link
Member

resolved_by_pr #23702

@ansibot ansibot added the traceback This issue/PR includes a traceback. label May 23, 2018
@ansibot
Copy link
Contributor

ansibot commented Oct 6, 2018

@ansibot
Copy link
Contributor

ansibot commented Nov 2, 2018

@ansibot
Copy link
Contributor

ansibot commented Dec 12, 2018

@felixfontein
Copy link
Contributor

Please note that the docker_service module will be renamed to docker_compose in Ansible 2.8. You will be able to still use the old name, but you will receive a warning when doing so.

!component =lib/ansible/modules/cloud/docker/docker_compose.py

Also, please note that currently, nobody is actively maintaining the Ansible docker_service/docker_compose modules. If you are interested in working on this issue, please feel free to create a PR :) If you need any help, feel free to ping me or any other of the current docker_* module maintainers.

@ansibot
Copy link
Contributor

ansibot commented Feb 4, 2019

@ansibot
Copy link
Contributor

ansibot commented Apr 9, 2019

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Apr 17, 2019
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 25, 2019
@sluther
Copy link
Contributor

sluther commented Jun 14, 2019

I will review the PR, verify that it fixes the issue, and create a new PR.

@ansibot ansibot added the has_pr This issue has an associated PR. label Jul 24, 2019
@ansibot ansibot added collection Related to Ansible Collections work collection:community.general needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 27, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 17, 2020

Thank you very much for your interest in Ansible. Ansible has migrated much of the content into separate repositories to allow for more rapid, independent development. We are closing this issue/PR because this content has been moved to one or more collection repositories.

For further information, please see:
https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md

@ansibot ansibot closed this as completed Aug 17, 2020
@ansible ansible locked and limited conversation to collaborators Sep 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants