Skip to content

Commit

Permalink
Pass etc_hosts through to docker_container module if set in molecule …
Browse files Browse the repository at this point in the history
…config (#1972)

* set etc_hosts in docker_container module if set in molecule config

Signed-off-by: Jeremy Zafran <[email protected]>

* Add test for etc_hosts

The "etc_hosts" is set to string for usability. More detail see,
https://stackoverflow.com/questions/39224679/ansible-docker-container-etc-hosts-with-variable-key

Signed-off-by: benjah1 <[email protected]>

* add type dict to etc_hosts and fix unit test

Signed-off-by: benjah1 <[email protected]>
  • Loading branch information
benjah1 authored and ssbarnea committed Jun 6, 2019
1 parent 9aaabee commit f6f986e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions molecule/driver/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Docker(base.Base):
- nofile:262144:262144
dns_servers:
- 8.8.8.8
etc_hosts: "{'host1.example.com': '10.3.1.5'}"
networks:
- name: foo
- name: bar
Expand Down
6 changes: 6 additions & 0 deletions molecule/model/schema_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ def pre_validate_base_schema(env, keep_string):
'type': 'string',
}
},
'etc_hosts': {
'type': ['string', 'dict'],
'keyschema': {
'type': 'string',
}
},
'env': {
'type': 'dict',
'keysrules': {
Expand Down
1 change: 1 addition & 0 deletions molecule/provisioner/ansible/playbooks/docker/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
network_mode: "{{ item.network_mode | default(omit) }}"
purge_networks: "{{ item.purge_networks | default(omit) }}"
dns_servers: "{{ item.dns_servers | default(omit) }}"
etc_hosts: "{{ item.etc_hosts | default(omit) }}"
env: "{{ item.env | default(omit) }}"
restart_policy: "{{ item.restart_policy | default(omit) }}"
restart_retries: "{{ item.restart_retries | default(omit) }}"
Expand Down
1 change: 1 addition & 0 deletions test/resources/playbooks/docker/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
network_mode: "{{ item.network_mode | default(omit) }}"
purge_networks: "{{ item.purge_networks | default(omit) }}"
dns_servers: "{{ item.dns_servers | default(omit) }}"
etc_hosts: "{{ item.etc_hosts | default(omit) }}"
env: "{{ item.env | default(omit) }}"
restart_policy: "{{ item.restart_policy | default(omit) }}"
restart_retries: "{{ item.restart_retries | default(omit) }}"
Expand Down
4 changes: 4 additions & 0 deletions test/unit/model/v2/test_platforms_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def _model_platforms_docker_section_data():
'dns_servers': [
'8.8.8.8',
],
'etc_hosts':
"{'host1.example.com': '10.3.1.5'}",
'env': {
'FOO': 'bar',
'foo': 'bar',
Expand Down Expand Up @@ -198,6 +200,7 @@ def _model_platforms_docker_errors_section_data():
'dns_servers': [
int(),
],
"etc_hosts": int(),
'env': str(),
'restart_policy': int(),
'restart_retries': str(),
Expand Down Expand Up @@ -269,6 +272,7 @@ def test_platforms_docker_has_errors(_config):
'ulimits': [{
0: ['must be of string type']
}],
'etc_hosts': ['must be of [\'string\', \'dict\'] type'],
'env': ['must be of dict type'],
'restart_policy': ['must be of string type'],
'restart_retries': ['must be of integer type'],
Expand Down

0 comments on commit f6f986e

Please sign in to comment.