summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/tacker/tasks/tacker_controller.yml
blob: f2c39bd7e097add6da1e3881f5994d9becf4043f (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
##############################################################################
# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
---
- name: edit ml2_conf.ini
  shell: |
    crudini --set /etc/neutron/plugins/ml2/ml2_conf.ini ml2 extension_drivers port_security;

- name: Restart neutron-server
  service: name=neutron-server state=restarted

- name: "create haproxy configuration for tacker"
  template:
    src: "haproxy-tacker-cfg.j2"
    dest: "/tmp/haproxy-tacker.cfg"

- name: get the current haproxy configuration
  shell: cat /etc/haproxy/haproxy.cfg
  register: ha_cfg

- name: "combination of the haproxy configuration"
  shell: "cat /tmp/haproxy-tacker.cfg >> /etc/haproxy/haproxy.cfg"
  when: ha_cfg.stdout.find('9890') == -1

- name: "delete temporary configuration file"
  file:
    dest: "/tmp/haproxy-tacker.cfg"
    state: "absent"

- name: "restart haproxy"
  service:
    name: "haproxy"
    state: "restarted"

- name: drop and recreate tacker database
  shell: |
    mysql -e "drop database if exists tacker;";
    mysql -e "create database tacker character set utf8;";
    mysql -e "grant all on tacker.* to 'tacker'@'%' identified by 'TACKER_DBPASS';";
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: get the openstack user info
  shell: . /opt/admin-openrc.sh; openstack user list
  register: user_info

- name: get the openstack service info
  shell: . /opt/admin-openrc.sh; openstack service list
  register: service_info

- name: get the openstack endpoint info
  shell: . /opt/admin-openrc.sh; openstack endpoint list
  register: endpoint_info

- name: delete the existed tacker endpoint
  shell: |
    . /opt/admin-openrc.sh;
    openstack endpoint delete \
        $(openstack endpoint list | grep tacker | awk '{print $2}')
  when: endpoint_info.stdout.find('tacker') != -1
        and inventory_hostname == haproxy_hosts.keys()[0]

- name: delete the existed tacker service
  shell: |
    . /opt/admin-openrc.sh;
    openstack service delete tacker;
  when: service_info.stdout.find('tacker') != -1
        and inventory_hostname == haproxy_hosts.keys()[0]

- name: delete the existed tacker user
  shell: |
    . /opt/admin-openrc.sh;
    openstack user delete tacker;
  when: user_info.stdout.find('tacker') != -1
        and inventory_hostname == haproxy_hosts.keys()[0]

- name: create tacker user with admin privileges
  shell: |
    . /opt/admin-openrc.sh;
    openstack user create --password console tacker;
    openstack role add --project service --user tacker admin;
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: creat tacker service
  shell: |
    . /opt/admin-openrc.sh;
    openstack service create --name tacker \
        --description "Tacker Project" nfv-orchestration
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: provide an endpoint to tacker service
  shell: |
    . /opt/admin-openrc.sh; \
    openstack endpoint create --region RegionOne \
        nfv-orchestration public 'http://{{ public_vip.ip }}:9890/';
    openstack endpoint create --region RegionOne \
        nfv-orchestration admin 'http://{{ internal_vip.ip }}:9890/';
    openstack endpoint create --region RegionOne \
        nfv-orchestration internal 'http://{{ internal_vip.ip }}:9890/';
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: install tacker and tacker client
  shell: |
    pip install tacker python-tackerclient

- name: create 'tacker' directory in '/var/cache'
  shell: |
    mkdir -p /var/cache/tacker

- name: create 'tacker' directory in '/var/log'
  shell: mkdir -p /var/log/tacker

- name: get the policy file of heat
  shell: cat /etc/heat/policy.json | grep Flavor
  register: heat_info

- name: update the policy file of heat
  lineinfile:
    dest: /etc/heat/policy.json
    regexp: '    "resource_types:OS::Nova::Flavor'
    line: '    "resource_types:OS::Nova::Flavor": "role:admin",'
  when: heat_info.stdout.find('role') == -1

- name: restart heat services
  service: name={{ item }} state=restarted enabled=yes
  with_items: "{{ heat_services }}"

- name: copy tacker configs
  template: src={{ item.src }} dest=/opt/os_templates
  with_items: "{{ tacker_configs_templates }}"

- name: edit tacker configuration file
  shell: |
    crudini --merge /usr/local/etc/tacker/tacker.conf \
        < /opt/os_templates/tacker.j2

- name: populate tacker database
  shell: |
    . /opt/admin-openrc.sh; \
    /usr/local/bin/tacker-db-manage \
        --config-file /usr/local/etc/tacker/tacker.conf upgrade head
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: create tacker service
  copy: src=tacker.service dest=/lib/systemd/system/

- name: create tacker service work dir
  file: path=/var/lib/tacker state=directory

- name: link the tacker service
  file:
    src: /lib/systemd/system/tacker.service
    dest: /etc/systemd/system/multi-user.target.wants/tacker.service
    state: link

- name: start tacker service
  shell: service tacker start

- name: create tackerc file
  template: src=tackerc.sh dest=/opt/tackerc.sh mode=777

- name: create nfvrc file
  template: src=nfvrc.sh dest=/opt/nfvrc.sh mode=777

- name: get the nfv_user info
  shell: . /opt/tackerc.sh; openstack user list
  register: nfvuser_info

- name: delete the existed nfv user
  shell: . /opt/tackerc.sh; openstack user delete nfv_user
  when: nfvuser_info.stdout.find('nfv') != -1 and inventory_hostname == haproxy_hosts.keys()[0]

- name: get the openstack project info
  shell: . /opt/tackerc.sh; openstack project list
  register: nfvproject_info

- name: delete the existed nfv project
  shell: |
    . /opt/tackerc.sh;
    openstack project delete $(openstack project list | grep nfv | awk '{print $2}')
  when: nfvproject_info.stdout.find('nfv') != -1 and inventory_hostname == haproxy_hosts.keys()[0]

- name: create an nfv project
  shell: . /opt/tackerc.sh; openstack project create --description "NFV Project" nfv
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: create nfv user with admin privileges
  shell: |
    . /opt/tackerc.sh;
    openstack user create --password console nfv_user;
    openstack role add --project nfv --user nfv_user admin;
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: create config.yml
  template: src=config.yaml dest=/opt/config.yaml

- name: check if tacker running
  shell: . /opt/tackerc.sh; while (!(tacker ext-list)); do sleep 30; done

- name: register VIM to tacker
  shell: |
    . /opt/tackerc.sh;
    tacker vim-register --config-file /opt/config.yaml --description "Default VIM" VIM0
  when: inventory_hostname == haproxy_hosts.keys()[0]

- name: restart tacker service
  shell: service tacker stop; service tacker start