Initial commit
[ta/infra-ansible.git] / roles / baremetal_provision / tasks / ironic_nodes_create.yml
1 ---
2
3 # Copyright 2019 Nokia
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: Checking the details of Provisioning images
18   stat:
19     path: "{{ item }}"
20     get_md5: no
21     get_checksum: no
22   with_items:
23     - "/opt/images/guest-image.img"
24   register: stat_list
25   no_log: True
26
27 - name: Change ownership of provisioning images
28   file:
29     path: "{{ item.stat.path }}"
30     owner: "ironic"
31     group: "ironic"
32   with_items: "{{stat_list.results}}"
33   when: item.stat.pw_name != 'ironic'
34   no_log: True
35
36 - name: Write os_net_config to tmp files
37   copy:
38     content: "{{ item.driver_info.power.os_net_config }}"
39     dest: "/tmp/{{item.name}}_config.yaml"
40     mode: 0444
41   with_items: "{{ baremetal_ironic_nodes }}"
42   loop_control:
43     label: "{{ item.name }}"
44
45 - name: Create baremetal ironic nodes
46   environment:
47     OS_AUTH_TOKEN: "fake-token"
48     IRONIC_URL: "{{ ironic_service_adminurl }}"
49   os_ironic:
50     auth:
51     auth_type: 'None'
52     ironic_url: "{{ ironic_service_adminurl }}"
53     state: present
54     name: "{{ item.1.name }}"
55     driver: "{{ item.1.driver }}"
56     nics: "{{ item.1.nics }}"
57     properties: "{{ item.1.properties }}"
58     driver_info: "{{ item.1.driver_info | combine({'power': {'os_net_config': lookup('file', '/tmp/'+item.1.name+'_config.yaml'), 'ipmi_terminal_port': hosts[item.1.name]['ipmi_terminal_port'] }}, recursive=True ) }}"
59   with_indexed_items: "{{ baremetal_ironic_nodes }}"
60   register: baremetal_ironic_nodes_results
61   when: installation_phase == "provisioning-started"
62   loop_control:
63     label: "{{ item.1.name }}"
64
65 - name: Create list of nodes which are not in active state and not the installation controller.
66   set_fact:
67     baremetal_ironic_nodes_ids: "{{ baremetal_ironic_nodes_ids  +  [{'uuid': item.uuid, 'name': item.item.1.name}] }}"
68   with_items: "{{ baremetal_ironic_nodes_results.results }}"
69   when:
70     - installation_phase == "provisioning-started"
71     - hosts[item.item.1.name]['installation_host'] is undefined
72     - item.provision_state != 'active'
73   no_log: True
74
75 - name: Create baremetal ironic nodes
76   os_ironic:
77     cloud: default
78     endpoint_type: internal
79     auth_type: password
80     state: present
81     name: "{{ item.1.name }}"
82     driver: "{{ item.1.driver }}"
83     nics: "{{ item.1.nics }}"
84     properties: "{{ item.1.properties }}"
85     driver_info: "{{ item.1.driver_info | combine({'power': {'os_net_config': lookup('file', '/tmp/'+item.1.name+'_config.yaml'), 'ipmi_terminal_port': hosts[item.1.name]['ipmi_terminal_port'] }}, recursive=True ) }}"
86   with_indexed_items: "{{ baremetal_ironic_nodes }}"
87   register: baremetal_ironic_nodes_results
88   when: (installation_phase != "provisioning-started" and reinitialized_nodes is not defined and scaled_out_nodes is not defined) or (reinitialized_nodes is defined and item.1.name in reinitialized_nodes) or (scaled_out_nodes is defined and item.1.name in scaled_out_nodes)
89   loop_control:
90     label: "{{ item.1.name }}"
91
92 - name: Create list of nodes which are not in active state and not the installation controller.
93   set_fact:
94     baremetal_ironic_nodes_ids: "{{ baremetal_ironic_nodes_ids  +  [{'uuid': item.uuid, 'name': item.item.1.name}] }}"
95   with_items: "{{ baremetal_ironic_nodes_results.results }}"
96   when:
97     - installation_phase != "provisioning-started"
98     - (hosts[item.item.1.name]['installation_host'] is undefined and reinitialized_nodes is not defined and scaled_out_nodes is not defined) or (reinitialized_nodes is defined and item.item.1.name in reinitialized_nodes) or (scaled_out_nodes is defined and item.item.1.name in scaled_out_nodes)
99     - item.provision_state != 'active'
100   no_log: True