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 |
| 6 | vars: |
| 7 | slice_name: "{{ slice_name }}" |
| 8 | user_name: "{{ user_name }}" |
| 9 | role: "{{ role }}" |
| 10 | tasks: |
| 11 | {% if delete -%} |
| 12 | {% else -%} |
| 13 | - name: Lookup local name of remote site |
| 14 | uri: |
| 15 | url: "{{ endpoint }}/api/core/sites/" |
| 16 | method: GET |
| 17 | user: "{{ admin_user }}" |
| 18 | password: "{{ admin_password }}" |
| 19 | return_content: yes |
| 20 | force_basic_auth: yes |
| 21 | register: sites |
| 22 | |
| 23 | - name: Save site name in local_site variable |
| 24 | set_fact: |
| 25 | local_site: "{{ '{{' }} sites.json[0]['name'] {{ '}}' }}" |
| 26 | |
| 27 | - name: Save local name of slice in local_slice_name variable |
| 28 | set_fact: |
| 29 | local_slice_name: "{{ '{{' }} local_site {{ '}}' }}_{{ slice_name }}" |
| 30 | |
| 31 | - name: Get list of users |
| 32 | uri: |
| 33 | url: "{{ endpoint }}/api/core/users/" |
| 34 | method: GET |
| 35 | user: "{{ admin_user }}" |
| 36 | password: "{{ admin_password }}" |
| 37 | return_content: yes |
| 38 | force_basic_auth: yes |
| 39 | register: users |
| 40 | |
| 41 | - fail: msg="User {{ user_name }} is not present at {{ endpoint }}" |
| 42 | when: not ((users.json | selectattr('username', 'equalto', user_name)) | list) |
| 43 | |
| 44 | - name: Get list of slices |
| 45 | uri: |
| 46 | url: "{{ endpoint }}/api/core/slices/" |
| 47 | method: GET |
| 48 | user: "{{ admin_user }}" |
| 49 | password: "{{ admin_password }}" |
| 50 | return_content: yes |
| 51 | force_basic_auth: yes |
| 52 | register: slices |
| 53 | |
| 54 | - fail: msg="Slice {{ slice_name }} is not present at {{ endpoint }}" |
| 55 | when: not ((slices.json | selectattr('name', 'equalto', local_slice_name)) | list) |
| 56 | |
| 57 | - name: Ensure TOSCA directory exists |
| 58 | file: |
| 59 | path=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/ |
| 60 | state=directory |
| 61 | |
| 62 | - name: Create TOSCA recipe from the template |
| 63 | template: |
| 64 | src=/opt/xos/synchronizers/globalxos/templates/slice_privileges.yaml.j2 |
| 65 | dest=/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml |
| 66 | |
| 67 | - name: Create slice privilege for "{{ slice }}" |
| 68 | uri: |
| 69 | url: "{{ endpoint }}/api/utility/tosca/run/" |
| 70 | method: POST |
| 71 | user: "{{ admin_user }}" |
| 72 | password: "{{ admin_password }}" |
| 73 | body: { "recipe": "{{ '{{' }} lookup('file', '/opt/xos/synchronizers/globalxos/tosca/slice_privileges/{{ ansible_tag }}.yml') {{ '}}' }}" } |
| 74 | force_basic_auth: yes |
| 75 | body_format: json |
| 76 | {% endif %} |