Ansible installer update
[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 - set_fact:
18     local_userdata: "{{ lookup('file', userdata_file) }}"
19   when: userdata_file != none
20
21 - name: Launch OSM instances
22   openstack.cloud.server:
23     cloud: "{{ cloud_name }}"
24     name: "{{ server_name }}-{{ item.name }}"
25     state: present
26     key_name: "{{ item.key }}"
27     nics: "{{ item.nics }}"
28     image: "{{ item.image }}"
29     flavor: "{{ item.flavor }}"
30     userdata: "{{ local_userdata }}"
31     security_groups:
32       - default
33       - "{{external_network_name}}_access"
34   with_items: "{{ servers }}"
35   register: "os_hosts"
36   when: setup_volume|bool == False
37
38 - name: Launch OSM instances with a volume
39   openstack.cloud.server:
40     cloud: "{{ cloud_name }}"
41     name: "{{ server_name }}-{{ item.name }}"
42     state: present
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 }}"
49     boot_from_volume: yes
50     terminate_volume: yes
51     security_groups:
52       - default
53       - "{{external_network_name}}_access"
54   with_items: "{{ servers }}"
55   register: "os_hosts_with_volume"
56   when: setup_volume|bool == True
57
58 - set_fact:
59     os_hosts: "{{ os_hosts_with_volume }}"
60   when: setup_volume|bool == True
61
62 - name: Add OSM host to the local Ansible inventory
63   add_host:
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
70
71 - name: Add OSM host to the local Ansible inventory
72   add_host:
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