Robert Kaussow
4ba1a83c0f
All checks were successful
continuous-integration/drone/push Build is passing
74 lines
2.6 KiB
YAML
74 lines
2.6 KiB
YAML
---
|
|
- name: Create
|
|
hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
#no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
|
|
vars:
|
|
ssh_port: 22
|
|
ssh_user: "{{ lookup('env', 'GCE_SSH_USER') }}"
|
|
ssh_identity_file: "{{ lookup('env', 'HOME') }}/.ssh/google_compute_engine"
|
|
tasks:
|
|
- name: Create molecule instance(s)
|
|
gce:
|
|
instance_names: "{{ item.name }}"
|
|
zone: "{{ item.zone }}"
|
|
machine_type: "{{ item.machine_type }}"
|
|
image: "{{ item.image }}"
|
|
service_account_email: "{{ lookup('env', 'GCE_SERVICE_ACCOUNT_EMAIL') }}"
|
|
credentials_file: "{{ lookup('env', 'GCE_CREDENTIALS_FILE') }}"
|
|
project_id: "{{ lookup('env', 'GCE_PROJECT_ID') }}"
|
|
register: server
|
|
with_items: "{{ molecule_yml.platforms }}"
|
|
loop_control:
|
|
label: "{{ item.name }}:{{ item.machine_type }}"
|
|
async: 7200
|
|
poll: 0
|
|
|
|
- name: Wait for instance(s) creation to complete
|
|
async_status:
|
|
jid: "{{ item.ansible_job_id }}"
|
|
register: gce_jobs
|
|
until: gce_jobs.finished
|
|
retries: 300
|
|
with_items: "{{ server.results }}"
|
|
loop_control:
|
|
label: "{{ item.item.name }}:{{ item.item.machine_type }}"
|
|
|
|
# Mandatory configuration for Molecule to function.
|
|
|
|
- name: Populate instance config dict
|
|
set_fact:
|
|
instance_conf_dict: {
|
|
'instance': "{{ item.instance_data[0].name }}",
|
|
'address': "{{ item.instance_data[0].public_ip }}",
|
|
'user': "{{ ssh_user }}",
|
|
'port': "{{ ssh_port }}",
|
|
'identity_file': "{{ ssh_identity_file }}", }
|
|
with_items: "{{ gce_jobs.results }}"
|
|
loop_control:
|
|
label: "{{ item.instance_data[0].name }}:{{ item.instance_data[0].machine_type }}"
|
|
register: instance_config_dict
|
|
when: server.changed | bool
|
|
|
|
- name: Convert instance config dict to a list
|
|
set_fact:
|
|
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
|
|
when: server.changed | bool
|
|
|
|
- name: Dump instance config
|
|
copy:
|
|
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
|
|
dest: "{{ molecule_instance_config }}"
|
|
when: server.changed | bool
|
|
|
|
- name: Wait for SSH
|
|
wait_for:
|
|
port: "{{ ssh_port }}"
|
|
host: "{{ item.address }}"
|
|
search_regex: SSH
|
|
delay: 10
|
|
with_items: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}"
|
|
loop_control:
|
|
label: "{{ item.instance }}"
|