| |
| # Copyright 2017-present Open Networking Foundation |
| # |
| # 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. |
| |
| |
| --- |
| - hosts: 127.0.0.1 |
| connection: local |
| # These variables are expanded by the Synchronizer framework |
| # and used to create the TOSCA recipe from a template |
| |
| tasks: |
| - name: Lookup local name of remote site |
| uri: |
| url: "{{ endpoint }}/api/core/sites/" |
| method: GET |
| user: "{{ admin_user }}" |
| password: "{{ admin_password }}" |
| return_content: yes |
| force_basic_auth: yes |
| register: sites |
| |
| - name: Save site name in local_site variable |
| set_fact: |
| local_site: "{{ sites.json[0]['name'] }}" |
| |
| - name: Save local name of slice in local_slice_name variable |
| set_fact: |
| local_slice_name: "{{ local_site }}_{{ slice_name }}" |
| |
| - name: Get list of users |
| uri: |
| url: "{{ endpoint }}/api/core/users/" |
| method: GET |
| user: "{{ admin_user }}" |
| password: "{{ admin_password }}" |
| return_content: yes |
| force_basic_auth: yes |
| register: users |
| |
| - fail: msg="User {{ user_name }} is not present at {{ endpoint }}" |
| when: not ((users.json | selectattr('username', 'equalto', user_name)) | list) |
| |
| - name: Get list of slices |
| uri: |
| url: "{{ endpoint }}/api/core/slices/" |
| method: GET |
| user: "{{ admin_user }}" |
| password: "{{ admin_password }}" |
| return_content: yes |
| force_basic_auth: yes |
| register: slices |
| |
| - fail: msg="Slice {{ slice_name }} is not present at {{ endpoint }}" |
| when: not ((slices.json | selectattr('name', 'equalto', local_slice_name)) | list) |
| |
| - name: Ensure TOSCA directory exists |
| file: |
| path=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/ |
| state=directory |
| |
| - name: Create TOSCA recipe from the template |
| template: |
| src=/opt/xos/synchronizers/globalxos/templates/slice_privileges.yaml.j2 |
| dest=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml |
| |
| - name: Create slice privilege for "{{ slice }}" |
| uri: |
| url: "{{ endpoint }}/api/utility/tosca/run/" |
| method: POST |
| user: "{{ admin_user }}" |
| password: "{{ admin_password }}" |
| body: { "recipe": "{{ lookup('file', '/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml') }}" } |
| force_basic_auth: yes |
| body_format: json |