Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 1 | --- |
| 2 | - hosts: 127.0.0.1 |
| 3 | connection: local |
| 4 | # These variables are expanded by the Synchronizer framework |
| 5 | # and used to create the TOSCA recipe from a template |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 6 | |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 7 | tasks: |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 8 | - name: Lookup local name of remote site |
| 9 | uri: |
| 10 | url: "{{ endpoint }}/api/core/sites/" |
| 11 | method: GET |
| 12 | user: "{{ admin_user }}" |
| 13 | password: "{{ admin_password }}" |
| 14 | return_content: yes |
| 15 | force_basic_auth: yes |
| 16 | register: sites |
| 17 | |
| 18 | - name: Save site name in local_site variable |
| 19 | set_fact: |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 20 | local_site: "{{ sites.json[0]['name'] }}" |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 21 | |
| 22 | - name: Save local name of slice in local_slice_name variable |
| 23 | set_fact: |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 24 | local_slice_name: "{{ local_site }}_{{ slice_name }}" |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 25 | |
| 26 | - name: Get list of users |
| 27 | uri: |
| 28 | url: "{{ endpoint }}/api/core/users/" |
| 29 | method: GET |
| 30 | user: "{{ admin_user }}" |
| 31 | password: "{{ admin_password }}" |
| 32 | return_content: yes |
| 33 | force_basic_auth: yes |
| 34 | register: users |
| 35 | |
| 36 | - fail: msg="User {{ user_name }} is not present at {{ endpoint }}" |
| 37 | when: not ((users.json | selectattr('username', 'equalto', user_name)) | list) |
| 38 | |
| 39 | - name: Get list of slices |
| 40 | uri: |
| 41 | url: "{{ endpoint }}/api/core/slices/" |
| 42 | method: GET |
| 43 | user: "{{ admin_user }}" |
| 44 | password: "{{ admin_password }}" |
| 45 | return_content: yes |
| 46 | force_basic_auth: yes |
| 47 | register: slices |
| 48 | |
| 49 | - fail: msg="Slice {{ slice_name }} is not present at {{ endpoint }}" |
| 50 | when: not ((slices.json | selectattr('name', 'equalto', local_slice_name)) | list) |
| 51 | |
| 52 | - name: Ensure TOSCA directory exists |
| 53 | file: |
| 54 | path=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/ |
| 55 | state=directory |
| 56 | |
| 57 | - name: Create TOSCA recipe from the template |
| 58 | template: |
| 59 | src=/opt/xos/synchronizers/globalxos/templates/slice_privileges.yaml.j2 |
| 60 | dest=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml |
| 61 | |
| 62 | - name: Create slice privilege for "{{ slice }}" |
| 63 | uri: |
| 64 | url: "{{ endpoint }}/api/utility/tosca/run/" |
| 65 | method: POST |
| 66 | user: "{{ admin_user }}" |
| 67 | password: "{{ admin_password }}" |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 68 | body: { "recipe": "{{ lookup('file', '/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml') }}" } |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 69 | force_basic_auth: yes |
| 70 | body_format: json |