blob: bc41643ec4084f84be4b5afc7e038ca0b892c986 [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
15- hosts: localhost
16 connection: local
17 gather_facts: false
18 no_log: "{{ molecule_no_log }}"
19 vars:
20 ssh_port: 22
21 stack_name: "{{ lookup('env', 'STACK_NAME') | default('atmosphere', True) }}"
22 identity_file: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/id_rsa"
23 tasks:
24 - name: create stack
25 openstack.cloud.stack:
26 name: "{{ stack_name }}"
27 template: heat/stack.yaml
28 register: _os_stack
29
30 - debug:
31 msg: "{{ _os_stack.stack }}"
32
33 - name: grab list of all ip addresses
34 ansible.builtin.set_fact:
35 key_pair: "{{ _os_stack.stack.outputs | json_query(key_query) | first }}"
36 controller_ips: "{{ _os_stack.stack.outputs | community.general.json_query(controller_query) | first }}"
37 storage_ips: "{{ _os_stack.stack.outputs | community.general.json_query(storage_query) | first }}"
38 compute_ips: "{{ _os_stack.stack.outputs | community.general.json_query(compute_query) | first }}"
39 vars:
40 key_query: "[?output_key=='key_pair'].output_value"
41 controller_query: "[?output_key=='controller_floating_ip_addresses'].output_value"
42 storage_query: "[?output_key=='storage_floating_ip_addresses'].output_value"
43 compute_query: "[?output_key=='compute_floating_ip_addresses'].output_value"
44
45 - name: wait for systems to go up
46 ansible.builtin.wait_for:
47 port: "22"
48 host: "{{ item }}"
49 search_regex: SSH
50 timeout: 60
51 loop: "{{ controller_ips + storage_ips + compute_ips }}"
52
53 - name: generate private key file
54 ansible.builtin.copy:
55 dest: "{{ identity_file }}"
56 content: "{{ key_pair }}"
57 mode: 0600
58
59 - name: generate instance config file
60 copy:
61 content: "{{ instance_config | to_yaml }}"
62 dest: "{{ molecule_instance_config }}"
63 vars:
64 base_instance_config: &instance_config
65 user: "ubuntu"
66 port: "{{ ssh_port }}"
67 identity_file: "{{ identity_file }}"
68 instance_config:
69 - <<: *instance_config
70 instance: "ctl1"
71 address: "{{ controller_ips[0] }}"
72 - <<: *instance_config
73 instance: "ctl2"
74 address: "{{ controller_ips[1] }}"
75 - <<: *instance_config
76 instance: "ctl3"
77 address: "{{ controller_ips[2] }}"
78 - <<: *instance_config
79 instance: "nvme1"
80 address: "{{ storage_ips[0] }}"
81 - <<: *instance_config
82 instance: "nvme2"
83 address: "{{ storage_ips[1] }}"
84 - <<: *instance_config
85 instance: "nvme3"
86 address: "{{ storage_ips[2] }}"
87 - <<: *instance_config
88 instance: "kvm1"
89 address: "{{ compute_ips[0] }}"
90 - <<: *instance_config
91 instance: "kvm2"
92 address: "{{ compute_ips[1] }}"