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') }}" |
| 18 | domain_name: "{{ '{{' }} hostvars['ctl1']['ansible_host'].replace('.', '-') {{ '}}' }}.nip.io" |
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) }}" |
| 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) }}" |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 33 | tasks: |
| 34 | - name: create stack |
| 35 | openstack.cloud.stack: |
| 36 | name: "{{ stack_name }}" |
| 37 | template: heat/stack.yaml |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 38 | parameters: |
| 39 | public_network: "{{ public_network }}" |
| 40 | image: "{{ image }}" |
| 41 | instance_type: "{{ instance_type }}" |
| 42 | nameservers: "{{ nameservers }}" |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 43 | register: _os_stack |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 44 | - debug: |
| 45 | msg: "{{ _os_stack.stack }}" |
| 46 | |
| 47 | - name: grab list of all ip addresses |
| 48 | ansible.builtin.set_fact: |
| 49 | key_pair: "{{ _os_stack.stack.outputs | json_query(key_query) | first }}" |
| 50 | controller_ips: "{{ _os_stack.stack.outputs | community.general.json_query(controller_query) | first }}" |
| 51 | storage_ips: "{{ _os_stack.stack.outputs | community.general.json_query(storage_query) | first }}" |
| 52 | compute_ips: "{{ _os_stack.stack.outputs | community.general.json_query(compute_query) | first }}" |
| 53 | vars: |
| 54 | key_query: "[?output_key=='key_pair'].output_value" |
| 55 | controller_query: "[?output_key=='controller_floating_ip_addresses'].output_value" |
| 56 | storage_query: "[?output_key=='storage_floating_ip_addresses'].output_value" |
| 57 | compute_query: "[?output_key=='compute_floating_ip_addresses'].output_value" |
| 58 | |
| 59 | - name: wait for systems to go up |
| 60 | ansible.builtin.wait_for: |
| 61 | port: "22" |
| 62 | host: "{{ item }}" |
| 63 | search_regex: SSH |
| 64 | timeout: 60 |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 65 | retries: 5 |
| 66 | delay: 10 |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 67 | loop: "{{ controller_ips + storage_ips + compute_ips }}" |
| 68 | |
| 69 | - name: generate private key file |
| 70 | ansible.builtin.copy: |
| 71 | dest: "{{ identity_file }}" |
| 72 | content: "{{ key_pair }}" |
| 73 | mode: 0600 |
| 74 | |
| 75 | - name: generate instance config file |
| 76 | copy: |
| 77 | content: "{{ instance_config | to_yaml }}" |
| 78 | dest: "{{ molecule_instance_config }}" |
| 79 | vars: |
| 80 | base_instance_config: &instance_config |
Michiel Piscaer | 97b7fd3 | 2022-03-17 12:15:21 +0100 | [diff] [blame] | 81 | user: "{{ lookup('env', 'ATMOSPHERE_USERNAME') | default('ubuntu', True) }}" |
Mohammed Naser | 336caf4 | 2022-03-11 17:56:45 -0500 | [diff] [blame] | 82 | port: "{{ ssh_port }}" |
| 83 | identity_file: "{{ identity_file }}" |
| 84 | instance_config: |
| 85 | - <<: *instance_config |
| 86 | instance: "ctl1" |
| 87 | address: "{{ controller_ips[0] }}" |
| 88 | - <<: *instance_config |
| 89 | instance: "ctl2" |
| 90 | address: "{{ controller_ips[1] }}" |
| 91 | - <<: *instance_config |
| 92 | instance: "ctl3" |
| 93 | address: "{{ controller_ips[2] }}" |
| 94 | - <<: *instance_config |
| 95 | instance: "nvme1" |
| 96 | address: "{{ storage_ips[0] }}" |
| 97 | - <<: *instance_config |
| 98 | instance: "nvme2" |
| 99 | address: "{{ storage_ips[1] }}" |
| 100 | - <<: *instance_config |
| 101 | instance: "nvme3" |
| 102 | address: "{{ storage_ips[2] }}" |
| 103 | - <<: *instance_config |
| 104 | instance: "kvm1" |
| 105 | address: "{{ compute_ips[0] }}" |
| 106 | - <<: *instance_config |
| 107 | instance: "kvm2" |
Mohammed Naser | 206e5f8 | 2022-03-16 20:21:14 -0400 | [diff] [blame] | 108 | address: "{{ compute_ips[1] }}" |