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 |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 6 | tasks: |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 7 | - name: Lookup local name of remote site |
| 8 | uri: |
| 9 | url: "{{ endpoint }}/api/core/sites/" |
| 10 | method: GET |
| 11 | user: "{{ admin_user }}" |
| 12 | password: "{{ admin_password }}" |
| 13 | return_content: yes |
| 14 | force_basic_auth: yes |
| 15 | register: sites |
| 16 | |
| 17 | - name: Save site name in local_site variable |
| 18 | set_fact: |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 19 | local_site: "{{ sites.json[0]['name'] }}" |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 20 | |
| 21 | - name: Get list of images |
| 22 | uri: |
| 23 | url: "{{ endpoint }}/api/core/images/" |
| 24 | method: GET |
| 25 | user: "{{ admin_user }}" |
| 26 | password: "{{ admin_password }}" |
| 27 | return_content: yes |
| 28 | force_basic_auth: yes |
| 29 | register: images |
| 30 | |
| 31 | - fail: msg="Image {{ image }} is not present at {{ endpoint }}" |
| 32 | when: not ((images.json | selectattr('name', 'equalto', image)) | list) |
| 33 | |
| 34 | - name: Get list of networks |
| 35 | uri: |
| 36 | url: "{{ endpoint }}/api/core/networks/" |
| 37 | method: GET |
| 38 | user: "{{ admin_user }}" |
| 39 | password: "{{ admin_password }}" |
| 40 | return_content: yes |
| 41 | force_basic_auth: yes |
| 42 | register: networks |
| 43 | |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 44 | - fail: msg="Network {{ item }} is not present at {{ endpoint }}" |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 45 | when: not ((networks.json | selectattr('name', 'equalto', item)) | list) |
| 46 | with_items: |
| 47 | - "management" |
| 48 | - "public" |
| 49 | |
| 50 | - name: Ensure TOSCA directory exists |
| 51 | file: |
| 52 | path=/opt/xos/synchronizers/globalxos/tosca/slices/ |
| 53 | state=directory |
| 54 | |
| 55 | - name: Create TOSCA recipe from the template |
| 56 | template: |
| 57 | src=/opt/xos/synchronizers/globalxos/templates/slice.yaml.j2 |
| 58 | dest=/opt/xos/synchronizers/globalxos/tosca/slices/{{ ansible_tag }}.yml |
| 59 | |
| 60 | - name: Create slice "{{ slice }}" |
| 61 | uri: |
| 62 | url: "{{ endpoint }}/api/utility/tosca/run/" |
| 63 | method: POST |
| 64 | user: "{{ admin_user }}" |
| 65 | password: "{{ admin_password }}" |
Sapan Bhatia | a6ae7d6 | 2017-02-09 16:49:22 -0800 | [diff] [blame^] | 66 | body: { "recipe": "{{ lookup('file', '/opt/xos/synchronizers/globalxos/tosca/slices/{{ ansible_tag }}.yml') }}" } |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 67 | force_basic_auth: yes |
| 68 | body_format: json |