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

All docker platforms of a single scenario get the same command set (introduced in #1771) #1780

Closed
zeitounator opened this issue Feb 26, 2019 · 2 comments · Fixed by #1785
Closed

Comments

@zeitounator
Copy link
Contributor

zeitounator commented Feb 26, 2019

Issue Type

  • Bug report

Molecule and Ansible details

ansible --version && molecule --version
ansible 2.7.8
  config file = None
  configured module search path = ['/home/olcla/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.7 (default, Oct 22 2018, 11:32:17) [GCC 8.2.0]
molecule, version 2.19.1.dev139

Molecule installation method (one of):

Ansible installation method (one of):

  • pip

Desired Behavior

Recent implementation of command_override for docker containers in #1771 is buggy.

Suppose I have more than one platform:

platforms:

  - name: container1
    image: thoteam/ansible-centos7-apache-java:latest
    command: /usr/sbin/init
    pull: true
    pre_build_image: true
    privileged: true
    published_ports:
      - 8090:443
    groups:
      - nexus
    networks: &nexus_networks
      - name: nexus_default

  - name: container2
    image: thoteam/ldap-server-mock:latest
    pull: true
    pre_build_image: true
    exposed_ports:
      - 3004
    volumes:
      - ${MOLECULE_PROJECT_DIRECTORY}/molecule/ldap-server-mock-conf.json:/srv/ldap-server-mock-conf.json
      - ${MOLECULE_PROJECT_DIRECTORY}/molecule/ldap-server-mock-users.json:/srv/ldap-server-mock-users.json
    groups:
      - mockldap
    networks: *nexus_networks

When I run molecule create with the above config, I'm expecting to see 2 running containers:

  • container1 running /usr/sbin/init
  • container2 running the default command (bash -c "while true; do sleep 10000; done")

Actual Behaviour

Both containers are running the default command.

This is related to the new task introduced in #1771 (https://github.com/decentral1se/molecule/blob/d5255917c11d10ed161f6ee346e645222f22af69/molecule/provisioner/ansible/playbooks/docker/create.yml#L58).

The set_fact calculating command_directive runs on localhost and loops other the molecule platforms. So the var gets overwritten on each pass and only the last value for the last platform gets recorded and used for all platforms when creating the containers in the next task

My 2 cent towards the solution:

- name: Determine the CMD directives per platforms
  set_fact:
    command_directives: >-
      {{
        command_directives | default({})
        | combine ( { item.name: item.command | default('bash -c "while true; do sleep 10000; done"') } )
      }}
  with_items: "{{ molecule_yml.platforms }}"
  when: item.override_command | default(true)

- name: Create molecule instance(s)
  docker_container:
  # .... #
    command: "{{ command_directives[item.name] | default(omit) }}"
@decentral1se
Copy link
Contributor

Aha, I see!

Thanks for the report @zeitounator! Early testing is much appreciated :)

I'll get a fix out for this fairly soon, I hope.

decentral1se added a commit to decentral1se/molecule that referenced this issue Feb 27, 2019
@decentral1se
Copy link
Contributor

OK, I've opened #1785 against this 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants