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

Module docker_service seems to create variables at runtime #33960

Closed
marioprudhomme opened this issue Dec 15, 2017 · 18 comments
Closed

Module docker_service seems to create variables at runtime #33960

marioprudhomme opened this issue Dec 15, 2017 · 18 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker 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.

Comments

@marioprudhomme
Copy link

marioprudhomme commented Dec 15, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

docker_service

ANSIBLE VERSION
ansible 2.4.2.0
  config file = /etc/ansible/env/dev/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Apr 20 2017, 12:13:37) [GCC 6.3.0]
CONFIGURATION

DEFAULT_HOST_LIST(/etc/ansible/env/dev/ansible.cfg) = [u'/etc/ansible/env/dev/inventory.yml']

OS / ENVIRONMENT

N/A

SUMMARY

Not sure if this is an intended feature by the owner or a bug.

When using the docker_service module with state: present, a new variable is created in the ansible runtime for each services defined in the docker-compose.yml file, containing the output of docker-compose up. This potentially overwrites variables already defined in ansible.

This also means that if i edit the docker-compose.yml file (oblivious of ansible), it can potentially break the ansible build when there are name conflicts between ansible variables and the name of services present in the docker-compose.yml file.

STEPS TO REPRODUCE
- name: Up formio container
  docker_service:
      project_src: /srv/formio
      state: present
EXPECTED RESULTS

No variables created by the module

ACTUAL RESULTS

A new formio variable gets created and overwrites the current formio variable, becausee the docker-compose.yml file has a service named formio.

version: '2.1'

volumes:
    mongodb_data:
        driver: local

    formio_data:
        driver: local

services:
    mongodb:
        image: mongo:3.4.3
        volumes:
            - mongodb_data:/data/db
        healthcheck:
            test: ['CMD-SHELL', 'echo "db.stats().ok" | mongo localhost/formioapp --quiet']
            interval: 5s
            timeout: 1s
            retries: 10

    *formio*:
        build: .
        depends_on:
            mongodb:
                condition: service_healthy
                ...
@ansibot
Copy link
Contributor

ansibot commented Dec 15, 2017

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Dec 15, 2017

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report cloud docker module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Dec 15, 2017
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Dec 15, 2017
@sivel
Copy link
Member

sivel commented Dec 15, 2017

Ref:

for service in self.project.services:

@marioprudhomme
Copy link
Author

marioprudhomme commented Dec 15, 2017

Potential fix:

Keep the current behavior for backward compatibility. Introduce a new optional attribute to allow the user to register a new fact name instead of assuming the compose service names.

- name: Up formio container
  docker_service:
      project_src: /srv/formio
      state: present
      fact: results

results would contain:

{
    "mongodb": {  as usual... },
    "formio": { as usual... }
}

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@oryband
Copy link

oryband commented Jul 25, 2018

can confirm this exact problem happens to me as well. broke my deployment.

oryband added a commit to kinecosystem/blockchain-ops that referenced this issue Jul 25, 2018
@ansibot
Copy link
Contributor

ansibot commented Oct 5, 2018

@ansibot
Copy link
Contributor

ansibot commented Nov 2, 2018

@ansibot
Copy link
Contributor

ansibot commented Dec 12, 2018

@ansibot
Copy link
Contributor

ansibot commented Jan 24, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@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

@felixfontein
Copy link
Contributor

Please note that the returned ansible_facts are deprecated for Ansible 2.8, and will be removed in Ansible 2.12. Also, maybe this helps. No idea whether this can be set on task level, though.

@ansibot
Copy link
Contributor

ansibot commented Apr 9, 2019

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

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

CC @sluther

@ansibot
Copy link
Contributor

ansibot commented Apr 26, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added module This issue/PR relates to a module. 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 26, 2019
@sluther
Copy link
Contributor

sluther commented Jun 14, 2019

If I'm following this correctly, formio is used to refer to the service up until the point when docker-compose up is run, at which point formio is then replaced with the result of the call to docker-compose up. This will cause issues later on when referencing the formio variable. The expected behavior is the result of docker-compose up being stored in a different variable so it doesn't overwrite the service definition. Do I have that right? If so, this seems like a critical bug.

@felixfontein
Copy link
Contributor

It's not replaced, but a ansible_facts with name formio is returned by the module, which will take precedence over other variables called formio in the playbook from that point on. That's a known (mis-)behavior of the module and I've deprecated it, see here.

Use another variable name for now, or tell Ansible to handle ansible_facts differently (forgot how that option is named).

@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 29, 2020
@ansibot
Copy link
Contributor

ansibot commented Aug 16, 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 16, 2020
@ansible ansible locked and limited conversation to collaborators Sep 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bot_closed bug This issue/PR relates to a bug. cloud collection:community.general collection Related to Ansible Collections work docker 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.
Projects
None yet
Development

No branches or pull requests

7 participants