xoxys.nginx/molecule/gce-centos-7/create.yml

74 lines
2.6 KiB
YAML
Raw Normal View History

2019-02-27 09:37:29 +00:00
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
2019-02-27 11:14:56 +00:00
#no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}"
2019-02-27 09:37:29 +00:00
vars:
ssh_port: 22
2019-02-27 13:06:42 +00:00
ssh_user: "{{ lookup('env', 'GCE_SSH_USER') }}"
2019-02-27 09:37:29 +00:00
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 }}"
2019-02-28 12:22:58 +00:00
loop_control:
2019-02-28 12:28:19 +00:00
label: "{{ item.name }}:{{ item.machine_type }}"
2019-02-27 09:37:29 +00:00
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 }}"
2019-02-28 12:22:58 +00:00
loop_control:
2019-02-28 12:28:19 +00:00
label: "{{ item.item.name }}:{{ item.item.machine_type }}"
2019-02-27 09:37:29 +00:00
# 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 }}"
2019-02-28 12:22:58 +00:00
loop_control:
2019-02-28 12:38:25 +00:00
label: "{{ item.instance_data[0].name }}:{{ item.instance_data[0].machine_type }}"
2019-02-27 09:37:29 +00:00
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 }}"
2019-02-28 12:22:58 +00:00
loop_control:
label: "{{ item.instance }}"