blob: ef20bdfcb647a390e751106fc5d26a659626556b [file] [log] [blame]
Mohammed Naser336caf42022-03-11 17:56:45 -05001# Copyright (c) 2022 VEXXHOST, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Mohammed Naser46e15522022-03-19 16:07:44 -040015- import_playbook: vexxhost.atmosphere.generate_workspace
Mohammed Naser206e5f82022-03-16 20:21:14 -040016 vars:
Mohammed Naser46e15522022-03-19 16:07:44 -040017 workspace_path: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}"
Michiel Piscaerb490d712022-04-08 11:02:40 +020018 domain_name: "{{ '{{' }} hostvars['ctl1']['ansible_host'].replace('.', '-') {{ '}}' }}.{{ lookup('env', 'ATMOSPHERE_DNS_SUFFIX_NAME') | default('nip.io', True) }}"
Mohammed Naser206e5f82022-03-16 20:21:14 -040019
Mohammed Naser336caf42022-03-11 17:56:45 -050020- hosts: localhost
21 connection: local
22 gather_facts: false
23 no_log: "{{ molecule_no_log }}"
24 vars:
25 ssh_port: 22
Mohammed Naser336caf42022-03-11 17:56:45 -050026 identity_file: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/id_rsa"
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010027
28 stack_name: "{{ lookup('env', 'ATMOSPHERE_STACK_NAME') | default('atmosphere', True) }}"
29 public_network: "{{ lookup('env', 'ATMOSPHERE_PUBLIC_NETWORK') | default('public', True) }}"
30 image: "{{ lookup('env', 'ATMOSPHERE_IMAGE') | default('Ubuntu 20.04.3 LTS (x86_64) [2021-10-04]', True) }}"
31 instance_type: "{{ lookup('env', 'ATMOSPHERE_INSTANCE_TYPE') | default('v3-standard-4', True) }}"
32 nameservers: "{{ lookup('env', 'ATMOSPHERE_NAMESERVERS') | default('1.1.1.1', True) }}"
ricolin703b2802022-05-16 02:29:26 +080033 boot_from_volume: "{{ lookup('env', 'ATMOSPHERE_BOOT_FROM_VOLUME') | bool }}"
Mohammed Naser336caf42022-03-11 17:56:45 -050034 tasks:
35 - name: create stack
36 openstack.cloud.stack:
37 name: "{{ stack_name }}"
38 template: heat/stack.yaml
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010039 parameters:
40 public_network: "{{ public_network }}"
41 image: "{{ image }}"
42 instance_type: "{{ instance_type }}"
43 nameservers: "{{ nameservers }}"
ricolin703b2802022-05-16 02:29:26 +080044 boot_from_volume: "{{ boot_from_volume }}"
Mohammed Naser336caf42022-03-11 17:56:45 -050045 register: _os_stack
Mohammed Naser336caf42022-03-11 17:56:45 -050046 - debug:
47 msg: "{{ _os_stack.stack }}"
48
49 - name: grab list of all ip addresses
50 ansible.builtin.set_fact:
51 key_pair: "{{ _os_stack.stack.outputs | json_query(key_query) | first }}"
52 controller_ips: "{{ _os_stack.stack.outputs | community.general.json_query(controller_query) | first }}"
53 storage_ips: "{{ _os_stack.stack.outputs | community.general.json_query(storage_query) | first }}"
54 compute_ips: "{{ _os_stack.stack.outputs | community.general.json_query(compute_query) | first }}"
55 vars:
56 key_query: "[?output_key=='key_pair'].output_value"
57 controller_query: "[?output_key=='controller_floating_ip_addresses'].output_value"
58 storage_query: "[?output_key=='storage_floating_ip_addresses'].output_value"
59 compute_query: "[?output_key=='compute_floating_ip_addresses'].output_value"
60
61 - name: wait for systems to go up
62 ansible.builtin.wait_for:
63 port: "22"
64 host: "{{ item }}"
65 search_regex: SSH
Michiel Piscaer8ded0f62022-06-05 21:04:59 +000066 timeout: 600
67 retries: 15
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010068 delay: 10
Mohammed Naser336caf42022-03-11 17:56:45 -050069 loop: "{{ controller_ips + storage_ips + compute_ips }}"
70
71 - name: generate private key file
72 ansible.builtin.copy:
73 dest: "{{ identity_file }}"
74 content: "{{ key_pair }}"
75 mode: 0600
76
77 - name: generate instance config file
78 copy:
79 content: "{{ instance_config | to_yaml }}"
80 dest: "{{ molecule_instance_config }}"
81 vars:
82 base_instance_config: &instance_config
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010083 user: "{{ lookup('env', 'ATMOSPHERE_USERNAME') | default('ubuntu', True) }}"
Mohammed Naser336caf42022-03-11 17:56:45 -050084 port: "{{ ssh_port }}"
85 identity_file: "{{ identity_file }}"
86 instance_config:
87 - <<: *instance_config
88 instance: "ctl1"
89 address: "{{ controller_ips[0] }}"
90 - <<: *instance_config
91 instance: "ctl2"
92 address: "{{ controller_ips[1] }}"
93 - <<: *instance_config
94 instance: "ctl3"
95 address: "{{ controller_ips[2] }}"
96 - <<: *instance_config
97 instance: "nvme1"
98 address: "{{ storage_ips[0] }}"
99 - <<: *instance_config
100 instance: "nvme2"
101 address: "{{ storage_ips[1] }}"
102 - <<: *instance_config
103 instance: "nvme3"
104 address: "{{ storage_ips[2] }}"
105 - <<: *instance_config
106 instance: "kvm1"
107 address: "{{ compute_ips[0] }}"
108 - <<: *instance_config
109 instance: "kvm2"
Michiel Piscaerb490d712022-04-08 11:02:40 +0200110 address: "{{ compute_ips[1] }}"