|
| 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 |
0 commit comments