blob: 90870412ab7b3b075fd164ced2363b9034c7c891 [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) }}"
ricolind50c2a82023-06-01 22:19:17 +080031 controller_instance_type: "{{ lookup('env', 'ATMOSPHERE_CONTROLLER_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-16')) }}"
32 compute_instance_type: "{{ lookup('env', 'ATMOSPHERE_COMPUTE_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-4')) }}"
33 storage_instance_type: "{{ lookup('env', 'ATMOSPHERE_STORAGE_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-4')) }}"
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010034 nameservers: "{{ lookup('env', 'ATMOSPHERE_NAMESERVERS') | default('1.1.1.1', True) }}"
ricolin703b2802022-05-16 02:29:26 +080035 boot_from_volume: "{{ lookup('env', 'ATMOSPHERE_BOOT_FROM_VOLUME') | bool }}"
ricolin1139bb02023-03-21 23:45:40 +080036 create_bastion_host: "{{ lookup('env', 'ATMOSPHERE_CREATE_BASTION_HOST') | bool }}"
Mohammed Naser336caf42022-03-11 17:56:45 -050037 tasks:
38 - name: create stack
39 openstack.cloud.stack:
40 name: "{{ stack_name }}"
41 template: heat/stack.yaml
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010042 parameters:
43 public_network: "{{ public_network }}"
44 image: "{{ image }}"
Oleksandr Kozachenkoc01ee522023-05-30 21:22:07 +020045 controller_instance_type: "{{ controller_instance_type }}"
46 compute_instance_type: "{{ compute_instance_type }}"
47 storage_instance_type: "{{ storage_instance_type }}"
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010048 nameservers: "{{ nameservers }}"
ricolin703b2802022-05-16 02:29:26 +080049 boot_from_volume: "{{ boot_from_volume }}"
ricolin1139bb02023-03-21 23:45:40 +080050 create_bastion_host: "{{ create_bastion_host }}"
Mohammed Naser336caf42022-03-11 17:56:45 -050051 register: _os_stack
Mohammed Naser336caf42022-03-11 17:56:45 -050052 - debug:
53 msg: "{{ _os_stack.stack }}"
54
55 - name: grab list of all ip addresses
56 ansible.builtin.set_fact:
57 key_pair: "{{ _os_stack.stack.outputs | json_query(key_query) | first }}"
58 controller_ips: "{{ _os_stack.stack.outputs | community.general.json_query(controller_query) | first }}"
59 storage_ips: "{{ _os_stack.stack.outputs | community.general.json_query(storage_query) | first }}"
60 compute_ips: "{{ _os_stack.stack.outputs | community.general.json_query(compute_query) | first }}"
61 vars:
62 key_query: "[?output_key=='key_pair'].output_value"
63 controller_query: "[?output_key=='controller_floating_ip_addresses'].output_value"
64 storage_query: "[?output_key=='storage_floating_ip_addresses'].output_value"
65 compute_query: "[?output_key=='compute_floating_ip_addresses'].output_value"
66
67 - name: wait for systems to go up
68 ansible.builtin.wait_for:
69 port: "22"
70 host: "{{ item }}"
71 search_regex: SSH
Michiel Piscaer8ded0f62022-06-05 21:04:59 +000072 timeout: 600
73 retries: 15
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010074 delay: 10
Mohammed Naser336caf42022-03-11 17:56:45 -050075 loop: "{{ controller_ips + storage_ips + compute_ips }}"
76
77 - name: generate private key file
78 ansible.builtin.copy:
79 dest: "{{ identity_file }}"
80 content: "{{ key_pair }}"
81 mode: 0600
82
83 - name: generate instance config file
84 copy:
85 content: "{{ instance_config | to_yaml }}"
86 dest: "{{ molecule_instance_config }}"
87 vars:
88 base_instance_config: &instance_config
Michiel Piscaer97b7fd32022-03-17 12:15:21 +010089 user: "{{ lookup('env', 'ATMOSPHERE_USERNAME') | default('ubuntu', True) }}"
Mohammed Naser336caf42022-03-11 17:56:45 -050090 port: "{{ ssh_port }}"
91 identity_file: "{{ identity_file }}"
92 instance_config:
93 - <<: *instance_config
94 instance: "ctl1"
95 address: "{{ controller_ips[0] }}"
96 - <<: *instance_config
97 instance: "ctl2"
98 address: "{{ controller_ips[1] }}"
99 - <<: *instance_config
100 instance: "ctl3"
101 address: "{{ controller_ips[2] }}"
102 - <<: *instance_config
103 instance: "nvme1"
104 address: "{{ storage_ips[0] }}"
105 - <<: *instance_config
106 instance: "nvme2"
107 address: "{{ storage_ips[1] }}"
108 - <<: *instance_config
109 instance: "nvme3"
110 address: "{{ storage_ips[2] }}"
111 - <<: *instance_config
112 instance: "kvm1"
113 address: "{{ compute_ips[0] }}"
114 - <<: *instance_config
115 instance: "kvm2"
Michiel Piscaerb490d712022-04-08 11:02:40 +0200116 address: "{{ compute_ips[1] }}"