a9165709581897bcf362c9171e6fc7c5d6d0fa7c
[releng-xci.git] / xci / playbooks / get-opnfv-scenario-requirements.yml
1 ---
2 # Copyright 2016, Rackspace US, Inc.
3 # Copyright 2017, SUSE LINUX GmbH.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 - name: Clone the scenario requirements
18   hosts: localhost
19   connection: local
20   gather_facts: true
21   vars_files:
22     - ../var/opnfv.yml
23   tasks:
24     - name: Remove existing scenario directories
25       file:
26         path: "{{ item[1] }}/{{ item[0].scenario }}"
27         state: absent
28       with_nested:
29         - "{{ scenarios }}"
30         - [ "{{ scenario_path_default }}", "{{ role_path_default }}" ]
31       loop_control:
32         label: "{{ item[0].scenario }}"
33
34     - name: Update scenarios with local overrides
35       set_fact:
36           scenarios: >
37             {%- for z in xci_scenarios_overrides -%}
38               {%- for x in scenarios if x.scenario == z.scenario  -%}
39                 {%- set _ = x.update(z) -%}
40               {%- endfor -%}
41             {%- endfor -%}
42             {{- scenarios -}}
43       with_items: "{{ xci_scenarios_overrides }}"
44       loop_control:
45         label: "{{ item.scenario }}"
46       when: xci_scenarios_overrides is defined
47
48     - name: Collect list of known scenarions
49       set_fact:
50         known_scenarios: >
51           {%- set scenario_names = [] -%}
52           {%- for x in scenarios -%}
53             {%- set _ = scenario_names.append(x.scenario) -%}
54           {%- endfor -%}
55           {{- scenario_names -}}
56       with_items: "{{ scenarios }}"
57       loop_control:
58         label: "{{ item.scenario }}"
59
60     - name: Fail if 'DEPLOY_SCENARIO' is not defined
61       fail:
62         msg: "DEPLOY_SCENARIO env variable is not defined so no scenario can be deployed"
63       when: deploy_scenario is not defined
64
65     - name: Ensure {{ deploy_scenario }} is a known XCI scenario
66       fail:
67         msg: "{{ deploy_scenario }} does not exist"
68       when: deploy_scenario not in known_scenarios
69
70     - name: Collect scenario information
71       set_fact:
72         xci_scenario: >
73           {%- set xci_scenario = {} -%}
74           {%- for x in scenarios if x.scenario == deploy_scenario -%}
75           {%-   for z in x.installers if z.installer == installer_type -%}
76           {%-     set _ = xci_scenario.update({'flavors': z.flavors}) -%}
77           {%-     set _ = xci_scenario.update({'distros': z.distros}) -%}
78           {%-   endfor -%}
79           {%- set _ = xci_scenario.update({'role': x.role | basename}) -%}
80           {%- endfor -%}
81           {{ xci_scenario }}
82
83     - name: Ensure local facts directory exists
84       file:
85         path: "/etc/ansible/facts.d"
86         state: directory
87       become: true
88
89     - name: Record scenario information
90       ini_file:
91         create: yes
92         section: scenarios
93         state: present
94         option: role
95         value:  "{{ xci_scenario.role | basename }}"
96         path: "/etc/ansible/facts.d/xci.fact"
97       become: true
98
99     - name: Fail if {{ deploy_scenario }} is not supported
100       fail:
101         msg:
102           - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
103           - ERROR! The {{ deploy_scenario }} scenario can't be deployed. This is because
104           - the {{ installer_type }} XCI installer or the {{ xci_flavor }} flavor or the {{ xci_distro }}
105           - distribution is not supported by this scenario. It may also be possible that
106           - this scenario doesn't exist at all or it's not listed in {{ scenario_file }}.
107           - ''
108           - This is a great chance for you to contribute to XCI ;-)
109           - ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110           - ''
111       when:
112           (xci_scenario['flavors'] is defined and xci_flavor not in xci_scenario['flavors']) or
113           (xci_scenario['distros'] is defined and xci_distro not in xci_scenario['distros'])
114
115     - name: Clone git repos
116       git:
117         repo: "{{ item.src }}"
118         dest: "{{ scenario_path_default }}/{{ item.scenario | default(item.src | basename) }}"
119         version: "{{ item.version | default('master') }}"
120         refspec: "{{ item.refspec | default(omit) }}"
121         update: true
122         force: true
123       with_items: "{{ scenarios }}"
124       register: git_clone
125       until: git_clone | success
126       retries: "{{ git_clone_retries }}"
127       delay: "{{ git_clone_retry_delay }}"
128       loop_control:
129         label: "{{ item.scenario }}"
130
131     - name: Plug in the scenario Ansible roles to XCI
132       synchronize:
133         src: "{{ scenario_path_default }}/{{ item.scenario }}/{{ item.role }}/"
134         dest: "{{ role_path_default }}/{{ item.role | basename }}"
135       with_items: "{{ scenarios }}"
136       loop_control:
137         label: "{{ item.scenario }}"
138
139   vars:
140     ansible_python_interpreter: "/usr/bin/python"
141     scenarios: "{{ lookup('file', scenario_file) | from_yaml }}"
142     scenario_file: '../opnfv-scenario-requirements.yml'
143     scenario_path_default: "{{ xci_scenarios_cache }}"
144     role_path_default: "{{ playbook_dir }}/roles"
145     git_clone_retries: 2
146     git_clone_retry_delay: 5