blob: 1ececaca01570a52e4aa536de42cd27f651f4443 [file] [log] [blame]
Matteo Scandolof5e10332017-08-08 13:05:25 -07001
2# Copyright 2017-present Open Networking Foundation
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
16
Andy Bavier89a95422016-11-02 14:38:39 -040017---
18- hosts: 127.0.0.1
19 connection: local
20 # These variables are expanded by the Synchronizer framework
21 # and used to create the TOSCA recipe from a template
Sapan Bhatiaa6ae7d62017-02-09 16:49:22 -080022
Andy Bavier89a95422016-11-02 14:38:39 -040023 tasks:
Andy Bavier89a95422016-11-02 14:38:39 -040024 - name: Lookup local name of remote site
25 uri:
26 url: "{{ endpoint }}/api/core/sites/"
27 method: GET
28 user: "{{ admin_user }}"
29 password: "{{ admin_password }}"
30 return_content: yes
31 force_basic_auth: yes
32 register: sites
33
34 - name: Save site name in local_site variable
35 set_fact:
Sapan Bhatiaa6ae7d62017-02-09 16:49:22 -080036 local_site: "{{ sites.json[0]['name'] }}"
Andy Bavier89a95422016-11-02 14:38:39 -040037
38 - name: Save local name of slice in local_slice_name variable
39 set_fact:
Sapan Bhatiaa6ae7d62017-02-09 16:49:22 -080040 local_slice_name: "{{ local_site }}_{{ slice_name }}"
Andy Bavier89a95422016-11-02 14:38:39 -040041
42 - name: Get list of users
43 uri:
44 url: "{{ endpoint }}/api/core/users/"
45 method: GET
46 user: "{{ admin_user }}"
47 password: "{{ admin_password }}"
48 return_content: yes
49 force_basic_auth: yes
50 register: users
51
52 - fail: msg="User {{ user_name }} is not present at {{ endpoint }}"
53 when: not ((users.json | selectattr('username', 'equalto', user_name)) | list)
54
55 - name: Get list of slices
56 uri:
57 url: "{{ endpoint }}/api/core/slices/"
58 method: GET
59 user: "{{ admin_user }}"
60 password: "{{ admin_password }}"
61 return_content: yes
62 force_basic_auth: yes
63 register: slices
64
65 - fail: msg="Slice {{ slice_name }} is not present at {{ endpoint }}"
66 when: not ((slices.json | selectattr('name', 'equalto', local_slice_name)) | list)
67
68 - name: Ensure TOSCA directory exists
69 file:
70 path=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/
71 state=directory
72
73 - name: Create TOSCA recipe from the template
74 template:
75 src=/opt/xos/synchronizers/globalxos/templates/slice_privileges.yaml.j2
76 dest=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml
77
78 - name: Create slice privilege for "{{ slice }}"
79 uri:
80 url: "{{ endpoint }}/api/utility/tosca/run/"
81 method: POST
82 user: "{{ admin_user }}"
83 password: "{{ admin_password }}"
Sapan Bhatiaa6ae7d62017-02-09 16:49:22 -080084 body: { "recipe": "{{ lookup('file', '/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml') }}" }
Andy Bavier89a95422016-11-02 14:38:39 -040085 force_basic_auth: yes
86 body_format: json