Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 1 | # 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 Naser | 46e1552 | 2022-03-19 16:07:44 -0400 | [diff] [blame] | 15 | - import_playbook: vexxhost.atmosphere.generate_workspace |
Mohammed Naser | 206e5f8 | 2022-03-16 20:21:14 -0400 | [diff] [blame] | 16 | vars: |
Mohammed Naser | 46e1552 | 2022-03-19 16:07:44 -0400 | [diff] [blame] | 17 | workspace_path: "{{ lookup('env', 'MOLECULE_SCENARIO_DIRECTORY') }}" |
Michiel Piscaer | b490d71 | 2022-04-08 11:02:40 +0200 | [diff] [blame] | 18 | domain_name: "{{ '{{' }} hostvars['ctl1']['ansible_host'].replace('.', '-') {{ '}}' }}.{{ lookup('env', 'ATMOSPHERE_DNS_SUFFIX_NAME') | default('nip.io', True) }}" |
Mohammed Naser | 206e5f8 | 2022-03-16 20:21:14 -0400 | [diff] [blame] | 19 | |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 20 | - hosts: localhost |
| 21 | connection: local |
| 22 | gather_facts: false |
| 23 | no_log: "{{ molecule_no_log }}" |
| 24 | vars: |
| 25 | ssh_port: 22 |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 26 | identity_file: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/id_rsa" |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 27 | |
| 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) }}" |
Michiel Piscaer | 0e4939b | 2023-08-08 15:28:30 +0200 | [diff] [blame] | 31 | bastion_instance_type: "{{ lookup('env', 'ATMOSPHERE_BASTION_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-4')) }}" |
ricolin | d50c2a8 | 2023-06-01 22:19:17 +0800 | [diff] [blame] | 32 | controller_instance_type: "{{ lookup('env', 'ATMOSPHERE_CONTROLLER_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-16')) }}" |
| 33 | compute_instance_type: "{{ lookup('env', 'ATMOSPHERE_COMPUTE_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-4')) }}" |
| 34 | storage_instance_type: "{{ lookup('env', 'ATMOSPHERE_STORAGE_INSTANCE_TYPE', default=lookup('env', 'ATMOSPHERE_INSTANCE_TYPE', default='v3-standard-4')) }}" |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 35 | nameservers: "{{ lookup('env', 'ATMOSPHERE_NAMESERVERS') | default('1.1.1.1', True) }}" |
ricolin | 703b280 | 2022-05-16 02:29:26 +0800 | [diff] [blame] | 36 | boot_from_volume: "{{ lookup('env', 'ATMOSPHERE_BOOT_FROM_VOLUME') | bool }}" |
ricolin | 1139bb0 | 2023-03-21 23:45:40 +0800 | [diff] [blame] | 37 | create_bastion_host: "{{ lookup('env', 'ATMOSPHERE_CREATE_BASTION_HOST') | bool }}" |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 38 | tasks: |
Oleksandr K | dc27347 | 2023-12-20 14:09:12 +0100 | [diff] [blame] | 39 | - name: Generate a SSH key for stack |
| 40 | community.crypto.openssh_keypair: |
| 41 | path: "{{ identity_file }}" |
| 42 | regenerate: full_idempotence |
| 43 | register: _os_stack_keypair |
| 44 | |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 45 | - name: create stack |
| 46 | openstack.cloud.stack: |
| 47 | name: "{{ stack_name }}" |
| 48 | template: heat/stack.yaml |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 49 | parameters: |
| 50 | public_network: "{{ public_network }}" |
| 51 | image: "{{ image }}" |
Michiel Piscaer | 0e4939b | 2023-08-08 15:28:30 +0200 | [diff] [blame] | 52 | bastion_instance_type: "{{ bastion_instance_type }}" |
Oleksandr Kozachenko | c01ee52 | 2023-05-30 21:22:07 +0200 | [diff] [blame] | 53 | controller_instance_type: "{{ controller_instance_type }}" |
| 54 | compute_instance_type: "{{ compute_instance_type }}" |
| 55 | storage_instance_type: "{{ storage_instance_type }}" |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 56 | nameservers: "{{ nameservers }}" |
ricolin | 703b280 | 2022-05-16 02:29:26 +0800 | [diff] [blame] | 57 | boot_from_volume: "{{ boot_from_volume }}" |
ricolin | 1139bb0 | 2023-03-21 23:45:40 +0800 | [diff] [blame] | 58 | create_bastion_host: "{{ create_bastion_host }}" |
Oleksandr K | dc27347 | 2023-12-20 14:09:12 +0100 | [diff] [blame] | 59 | public_key_pair: "{{ _os_stack_keypair.public_key }}" |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 60 | register: _os_stack |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 61 | - debug: |
| 62 | msg: "{{ _os_stack.stack }}" |
| 63 | |
| 64 | - name: grab list of all ip addresses |
| 65 | ansible.builtin.set_fact: |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 66 | controller_ips: "{{ _os_stack.stack.outputs | community.general.json_query(controller_query) | first }}" |
| 67 | storage_ips: "{{ _os_stack.stack.outputs | community.general.json_query(storage_query) | first }}" |
| 68 | compute_ips: "{{ _os_stack.stack.outputs | community.general.json_query(compute_query) | first }}" |
| 69 | vars: |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 70 | controller_query: "[?output_key=='controller_floating_ip_addresses'].output_value" |
| 71 | storage_query: "[?output_key=='storage_floating_ip_addresses'].output_value" |
| 72 | compute_query: "[?output_key=='compute_floating_ip_addresses'].output_value" |
| 73 | |
| 74 | - name: wait for systems to go up |
| 75 | ansible.builtin.wait_for: |
| 76 | port: "22" |
| 77 | host: "{{ item }}" |
| 78 | search_regex: SSH |
Michiel Piscaer | 8ded0f6 | 2022-06-05 21:04:59 +0000 | [diff] [blame] | 79 | timeout: 600 |
| 80 | retries: 15 |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 81 | delay: 10 |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 82 | loop: "{{ controller_ips + storage_ips + compute_ips }}" |
| 83 | |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 84 | - name: generate instance config file |
| 85 | copy: |
| 86 | content: "{{ instance_config | to_yaml }}" |
| 87 | dest: "{{ molecule_instance_config }}" |
| 88 | vars: |
| 89 | base_instance_config: &instance_config |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 90 | user: "{{ lookup('env', 'ATMOSPHERE_USERNAME') | default('ubuntu', True) }}" |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 91 | port: "{{ ssh_port }}" |
| 92 | identity_file: "{{ identity_file }}" |
| 93 | instance_config: |
| 94 | - <<: *instance_config |
| 95 | instance: "ctl1" |
| 96 | address: "{{ controller_ips[0] }}" |
| 97 | - <<: *instance_config |
| 98 | instance: "ctl2" |
| 99 | address: "{{ controller_ips[1] }}" |
| 100 | - <<: *instance_config |
| 101 | instance: "ctl3" |
| 102 | address: "{{ controller_ips[2] }}" |
| 103 | - <<: *instance_config |
| 104 | instance: "nvme1" |
| 105 | address: "{{ storage_ips[0] }}" |
| 106 | - <<: *instance_config |
| 107 | instance: "nvme2" |
| 108 | address: "{{ storage_ips[1] }}" |
| 109 | - <<: *instance_config |
| 110 | instance: "nvme3" |
| 111 | address: "{{ storage_ips[2] }}" |
| 112 | - <<: *instance_config |
| 113 | instance: "kvm1" |
| 114 | address: "{{ compute_ips[0] }}" |
| 115 | - <<: *instance_config |
| 116 | instance: "kvm2" |
Michiel Piscaer | b490d71 | 2022-04-08 11:02:40 +0200 | [diff] [blame] | 117 | address: "{{ compute_ips[1] }}" |