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