Feature 8623
[osm/devops.git] / installers / openstack / roles / create_instances / tasks / main.yml
1 ---
2 #   Copyright 2020 British Telecommunications plc
3 #
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #   Unless required by applicable law or agreed to in writing, software
11 #   distributed under the License is distributed on an "AS IS" BASIS,
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #   See the License for the specific language governing permissions and
14 #   limitations under the License.
15 #   Author: Antonio Marsico (antonio.marsico@bt.com)
16
17 - name: Launch OSM instances
18   os_server:
19     cloud: "{{ cloud_name }}"
20     name: "{{ prefix }}-{{ item.name }}"
21     state: present
22     key_name: "{{ item.key }}"
23     nics: "{{ item.nics }}"
24     image: "{{ item.image }}"
25     flavor: "{{ item.flavor }}"
26     security_groups:
27       - default
28       - "{{external_network_name}}_access"
29   with_items: "{{ servers }}"
30   register: "os_hosts"
31   when: setup_volume|bool == False
32
33 - name: Launch OSM instances with a volume
34   os_server:
35     cloud: "{{ cloud_name }}"
36     name: "{{ prefix }}-{{ item.name }}"
37     state: present
38     key_name: "{{ item.key }}"
39     nics: "{{ item.nics }}"
40     image: "{{ item.image }}"
41     flavor: "{{ item.flavor }}"
42     boot_from_volume: yes
43     terminate_volume: yes
44     security_groups:
45       - default
46       - "{{external_network_name}}_access"
47   with_items: "{{ servers }}"
48   register: "os_hosts_with_volume"
49   when: setup_volume|bool == True
50
51 - set_fact:
52     os_hosts: "{{ os_hosts_with_volume }}"
53   when: setup_volume|bool == True
54
55 - name: Add OSM host to the local Ansible inventory
56   add_host:
57     name: "{{ item.openstack.accessIPv4 }}"
58     groups: "{{ item['item']['meta']['group'] }}"
59     ansible_private_key_file: "~/.ssh/{{ os_key_name }}"
60     ansible_user: "{{ item['item']['user'] }}"
61   with_items: "{{ os_hosts.results }}"