2 # Copyright 2020 British Telecommunications plc
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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)
18 local_userdata: "{{ lookup('file', userdata_file) }}"
19 when: userdata_file != none
21 - name: Launch OSM instances
22 openstack.cloud.server:
23 cloud: "{{ cloud_name }}"
24 name: "{{ server_name }}-{{ item.name }}"
26 key_name: "{{ item.key }}"
27 nics: "{{ item.nics }}"
28 image: "{{ item.image }}"
29 flavor: "{{ item.flavor }}"
30 userdata: "{{ local_userdata }}"
33 - "{{external_network_name}}_access"
34 with_items: "{{ servers }}"
36 when: setup_volume|bool == False
38 - name: Launch OSM instances with a volume
39 openstack.cloud.server:
40 cloud: "{{ cloud_name }}"
41 name: "{{ server_name }}-{{ item.name }}"
43 key_name: "{{ item.key }}"
44 nics: "{{ item.nics }}"
45 image: "{{ item.image }}"
46 flavor: "{{ item.flavor }}"
47 volume_size: "{{ os_flavor.disk }}"
48 userdata: "{{ local_userdata }}"
53 - "{{external_network_name}}_access"
54 with_items: "{{ servers }}"
55 register: "os_hosts_with_volume"
56 when: setup_volume|bool == True
59 os_hosts: "{{ os_hosts_with_volume }}"
60 when: setup_volume|bool == True
62 - name: Add OSM host to the local Ansible inventory
64 name: "{{ item.openstack.accessIPv4 }}"
65 groups: "{{ item['item']['meta']['group'] }}"
66 ansible_private_key_file: "~/.ssh/{{ os_key_name }}"
67 ansible_user: "{{ item['item']['user'] }}"
68 with_items: "{{ os_hosts.results }}"
69 when: key_file == none
71 - name: Add OSM host to the local Ansible inventory
73 name: "{{ item.openstack.accessIPv4 }}"
74 groups: "{{ item['item']['meta']['group'] }}"
75 ansible_private_key_file: "{{ key_file | regex_replace('.pub') }}"
76 ansible_user: "{{ item['item']['user'] }}"
77 with_items: "{{ os_hosts.results }}"
78 when: key_file != none