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