From 0d752c5b9f16e426fc4b6a7c060b6504241dcac8 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Wed, 27 Feb 2019 19:52:00 +0100 Subject: [PATCH] Fix `override_command` to support multiple platforms Closes https://github.com/ansible/molecule/issues/1780. Signed-off-by: Luke Murphy --- molecule/provisioner/ansible/playbooks/docker/create.yml | 9 ++++++--- test/resources/playbooks/docker/create.yml | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/molecule/provisioner/ansible/playbooks/docker/create.yml b/molecule/provisioner/ansible/playbooks/docker/create.yml index ce5c68343c..d05b96efde 100644 --- a/molecule/provisioner/ansible/playbooks/docker/create.yml +++ b/molecule/provisioner/ansible/playbooks/docker/create.yml @@ -55,9 +55,12 @@ state: present with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}" - - name: Determine the CMD directive + - name: Determine the CMD directives set_fact: - command_directive: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}" + command_directives_dict: >- + {{ command_directives_dict | 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) @@ -70,7 +73,7 @@ state: started recreate: false log_driver: json-file - command: "{{ command_directive | default(omit) }}" + command: "{{ command_directives_dict[item.name] | default(omit) }}" pid_mode: "{{ item.pid_mode | default(omit) }}" privileged: "{{ item.privileged | default(omit) }}" security_opts: "{{ item.security_opts | default(omit) }}" diff --git a/test/resources/playbooks/docker/create.yml b/test/resources/playbooks/docker/create.yml index fcef3d41a8..21f33856f3 100644 --- a/test/resources/playbooks/docker/create.yml +++ b/test/resources/playbooks/docker/create.yml @@ -55,9 +55,12 @@ state: present with_items: "{{ molecule_yml.platforms | molecule_get_docker_networks }}" - - name: Determine the CMD directive + - name: Determine the CMD directives set_fact: - command_directive: "{{ item.command | default('bash -c \"while true; do sleep 10000; done\"') }}" + command_directives_dict: >- + {{ command_directives_dict | 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) @@ -70,7 +73,7 @@ state: started recreate: false log_driver: json-file - command: "{{ command_directive | default(omit) }}" + command: "{{ command_directives_dict[item.name] | default(omit) }}" pid_mode: "{{ item.pid_mode | default(omit) }}" privileged: "{{ item.privileged | default(omit) }}" security_opts: "{{ item.security_opts | default(omit) }}"