Skip to content

Commit 4e414fc

Browse files
committed
https://github.com/ansible-community/molecule/issues/2560
1 parent 92ae61c commit 4e414fc

31 files changed

+4023
-67
lines changed
File renamed without changes.

molecule/centos-7/create.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
- name: Create
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
7+
tasks:
8+
- name: Create molecule instance(s)
9+
molecule_vagrant:
10+
instance_name: "{{ item.name }}"
11+
instance_interfaces: "{{ item.interfaces | default(omit) }}"
12+
instance_raw_config_args: "{{ item.instance_raw_config_args | default(omit) }}"
13+
14+
config_options: "{{ item.config_options | default(omit) }}"
15+
16+
platform_box: "{{ item.box }}"
17+
platform_box_version: "{{ item.box_version | default(omit) }}"
18+
platform_box_url: "{{ item.box_url | default(omit) }}"
19+
20+
provider_name: "{{ molecule_yml.driver.provider.name }}"
21+
provider_memory: "{{ item.memory | default(omit) }}"
22+
provider_cpus: "{{ item.cpus | default(omit) }}"
23+
provider_options: "{{ item.provider_options | default(omit) }}"
24+
provider_raw_config_args: "{{ item.provider_raw_config_args | default(omit) }}"
25+
provider_override_args: "{{ item.provider_override_args | default(omit) }}"
26+
27+
provision: "{{ item.provision | default(omit) }}"
28+
29+
state: up
30+
register: server
31+
with_items: "{{ molecule_yml.platforms }}"
32+
33+
# NOTE(retr0h): Vagrant/VBox sucks and parallelizing instance creation
34+
# causes issues.
35+
36+
# Mandatory configuration for Molecule to function.
37+
38+
- name: Populate instance config dict
39+
set_fact:
40+
instance_conf_dict: {
41+
'instance': "{{ item.Host }}",
42+
'address': "{{ item.HostName }}",
43+
'user': "{{ item.User }}",
44+
'port': "{{ item.Port }}",
45+
'identity_file': "{{ item.IdentityFile }}", }
46+
with_items: "{{ server.results }}"
47+
register: instance_config_dict
48+
when: server is changed
49+
50+
- name: Convert instance config dict to a list
51+
set_fact:
52+
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
53+
when: server is changed
54+
55+
- name: Dump instance config
56+
copy:
57+
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
58+
dest: "{{ molecule_instance_config }}"
59+
when: server is changed

molecule/centos-7/destroy.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: Destroy
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
7+
tasks:
8+
- name: Destroy molecule instance(s)
9+
molecule_vagrant:
10+
instance_name: "{{ item.name }}"
11+
platform_box: "{{ item.box }}"
12+
provider_name: "{{ molecule_yml.driver.provider.name }}"
13+
provider_options: "{{ item.provider_options | default(omit) }}"
14+
provider_raw_config_args: "{{ item.provider_raw_config_args | default(omit) }}"
15+
force_stop: "{{ item.force_stop | default(true) }}"
16+
17+
state: destroy
18+
register: server
19+
with_items: "{{ molecule_yml.platforms }}"
20+
21+
# NOTE(retr0h): Vagrant/VBox sucks and parallelizing instance deletion
22+
# causes issues.
23+
24+
# Mandatory configuration for Molecule to function.
25+
26+
- name: Populate instance config
27+
set_fact:
28+
instance_conf: {}
29+
30+
- name: Dump instance config
31+
copy:
32+
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
33+
dest: "{{ molecule_instance_config }}"
34+
when: server is changed

0 commit comments

Comments
 (0)