summaryrefslogtreecommitdiffstats
path: root/ansible/roles/infra_deploy_openstack/tasks/main.yml
blob: ba5d5bc54d11fa81fc5f3ba93c7715860ad45356 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Copyright (c) 2018 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
# This script is based on https://docs.openstack.org/kolla-ansible/pike/user/quickstart.html
- name: Include variables
  include_vars:
    file: "{{ rs_file }}"
    name: infra_deploy_vars

- set_fact:
    traffic_ip: "{{ item.interfaces[1].ip }}"
  when: item.hostname == ansible_host
  with_items: "{{ infra_deploy_vars.nodes }}"

- name: Get neutron iface
  set_fact:
    neutron_iface: "{{ item }}"
  when:
    - hostvars[ansible_host]['ansible_' + item.replace('-', '_')].ipv4 is defined
    - hostvars[ansible_host]['ansible_' + item.replace('-', '_')].ipv4.address is defined
    - hostvars[ansible_host]['ansible_' + item.replace('-', '_')].ipv4.address == traffic_ip
  with_items: "{{ hostvars[ansible_host].ansible_interfaces }}"

- name: Create a registry container
  docker_container:
    name: registry
    image: registry:2
    restart_policy: always
    ports:
    - "4000:5000"

- name: Download and install Kolla
  include_tasks: install_kolla.yml

- name: Configure Kolla
  include_tasks: configure_kolla.yml

- name: Configure Open Stack
  include_tasks: configure_openstack.yml

- name: Ramp up Open Stack
  include_tasks: rampup_openstack.yml

- name: Update admin-openrc.sh
  lineinfile:
    path: /etc/kolla/admin-openrc.sh
    regexp: "{{ item.find }}"
    line: "{{ item.add }}"
  with_items:
   - { find: 'EXTERNAL_NETWORK', add: 'export EXTERNAL_NETWORK=public' }
   - { find: 'OS_AUTH_TYPE', add: 'export OS_AUTH_TYPE=password' }

- name: Copy env file
  shell: cp /etc/kolla/admin-openrc.sh /tmp/admin-openrc.yaml

- name: Rework as env vars
  replace:
    path: /tmp/admin-openrc.yaml
    regexp: 'export\s+(.*)=(.*)'
    replace: '\1: \2'

- name: Download OpenStack env file
  fetch:
    src: /tmp/admin-openrc.yaml
    dest: /tmp/
    flat: yes

- include_vars:
    file: /tmp/admin-openrc.yaml
    name: ostack_env

- name: Re-assign IP address
  shell: ip address show {{ neutron_iface }} | awk '/inet/ {print $2}'
  when: neutron_iface is defined
  register: ip_netmask

- shell: >
    ip addr del dev {{ neutron_iface }} {{ ip_netmask.stdout }} &&
    ip addr add dev br-ex {{ infra_deploy_vars.networks[1].host_ip }}/{{ ip_netmask.stdout_lines[0].split('/')[1] }}
  when:
    - neutron_iface is defined
    - ip_netmask.stdout | length > 0

- name: Create external network
  os_network:
    name: public
    external: yes
    provider_physical_network: physnet1
    provider_network_type: flat
  environment:
    - no_proxy: "{{ lookup('env', 'no_proxy') + ',' + ansible_host + ',' + hostvars[ansible_host].ansible_default_ipv4.address }}"
    - "{{ ostack_env }}"

- name: Create sub-network
  os_subnet:
    name: public-subnet
    network_name: public
    cidr: "{{ ip_netmask.stdout }}"
    allocation_pool_start: "{{ infra_deploy_vars.networks[1].dhcp_ip_start }}"
    allocation_pool_end: "{{ infra_deploy_vars.networks[1].dhcp_ip_stop }}"
    gateway_ip: "{{ infra_deploy_vars.networks[1].host_ip }}"
    enable_dhcp: no
  environment:
    - no_proxy: "{{ lookup('env', 'no_proxy') + ',' + ansible_host + ',' + hostvars[ansible_host].ansible_default_ipv4.address }}"
    - "{{ ostack_env }}"

- name: Upload OpenStack env file to Yardstick VM
  copy:
    src: /etc/kolla/admin-openrc.sh
    dest: '/tmp/admin-openrc.sh'
    delegate_to: "{{ item }}"
  when: "groups['yardstickG'] is defined"
  with_items:
    - "{{ groups['yardstickG'] }}"