forked from jriguera/ansible-ironic-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-baremetal.yml
140 lines (124 loc) · 5.91 KB
/
add-baremetal.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
- name: Define and deploy physical servers using Ironic
hosts: ironic-api
become: yes
vars_prompt:
- name: "id"
prompt: "Server Name"
private: no
- name: "deploy"
prompt: "Deploy the server (y) or enroll (n)?"
private: no
default: "y"
pre_tasks:
- name: "Load Ironic (encrypted) variables"
include_vars: "{{ item }}"
with_first_found:
- "vars/{{ deployment }}/Ironic.yml"
- "vars/Ironic.yml"
- name: "Load (encrypted) baremetal variables"
include_vars: "{{ item }}"
with_first_found:
- "vars/{{ deployment }}/Baremetal.yml"
- "vars/Baremetal.yml"
# Minimun set of variables required, defaults are taken from the previous load
- name: Load hostvars
set_fact:
baremetal_ipmi_ip: "{{ hostvars[id]['baremetal_ipmi_ip'] | default(Baremetal_ipmi_ip) }}"
baremetal_ipmi_user: "{{ hostvars[id]['baremetal_ipmi_user'] | default(Baremetal_ipmi_user) }}"
baremetal_ipmi_pass: "{{ hostvars[id]['baremetal_ipmi_pass'] | default(Baremetal_ipmi_pass) }}"
baremetal_os: "{{ hostvars[id]['baremetal_os'] | default(Baremetal_os) }}"
baremetal_macs: "{{ hostvars[id]['baremetal_macs'] | default(Baremetal_macs) }}"
baremetal_network: "{{ hostvars[id]['baremetal_network'] | default(Baremetal_network) }}"
baremetal_fqdn: "{{ hostvars[id]['baremetal_fqdn'] | default(Baremetal_fqdn) }}"
baremetal_domain: "{{ hostvars[id]['baremetal_domain'] | default(Baremetal_domain) }}"
baremetal_name: "{{ hostvars[id]['baremetal_name'] | default(Baremetal_name) }}"
baremetal_console_port: "{{ hostvars[id]['baremetal_console_port'] | default(Baremetal_console_port) }}"
baremetal_cloudconfig: "{{ hostvars[id]['baremetal_cloudconfig'] | default(Baremetal_cloudconfig) }}"
baremetal_ssh_public_key: "{{ hostvars[id]['baremetal_ssh_public_key'] | default(Baremetal_ssh_public_key) }}"
baremetal_ssh_public_key_path: "{{ hostvars[id]['baremetal_ssh_public_key_path'] | default(Baremetal_ssh_public_key_path) }}"
baremetal_use_configdrive: "{{ hostvars[id]['baremetal_use_configdrive'] | default(Baremetal_use_configdrive) }}"
- name: Load image variable definitions
include_vars: "{{ item }}"
with_first_found:
- "vars/{{ deployment }}/images/{{ baremetal_os }}.yml"
- "vars/images/{{ baremetal_os }}.yml"
# Sanity checks of the variables and check Ironic server definition
- include: tasks/baremetal_prepare.yml _baremetal_create=true
when: id != 'vbox'
# Sanity checks of the variables and check Ironic server definition
- include: tasks/baremetal_vbox.yml _baremetal_create=true
when: id == 'vbox'
- include: tasks/baremetal_md5.yml
when: baremetal_image_checksum is not defined or not baremetal_image_checksum
- include: tasks/baremetal_configdrive.yml
when: baremetal_use_configdrive
roles:
- role: configdrive
configdrive_os_family: "{{ baremetal_image_type }}"
configdrive_uuid: "{{ baremetal_uuid }}"
configdrive_fqdn: "{{ baremetal_name }}.{{ baremetal_domain }}"
configdrive_name: "{{ baremetal_name }}"
configdrive_config_user_data_path: "{{ baremetal_cloudconfig }}"
configdrive_config_dir: "{{ Ironic_metadata_path }}"
configdrive_volume_path: "{{ Ironic_metadata_path }}"
configdrive_network_device_list: "{{ baremetal_network }}"
configdrive_ssh_public_key: "{{ baremetal_ssh_public_key }}"
configdrive_ssh_public_key_path: "{{ baremetal_ssh_public_key_path }}"
configdrive_volume_ext: ".cfgd"
configdrive_volume: true
configdrive_meta:
deploy_date: "{{ ansible_date_time.iso8601 }}"
deploy_host: "{{ ansible_hostname }}"
when: baremetal_use_configdrive
tasks:
- name: Define the install image for the node
command: >
ironic
--os-auth-token="{{ Ironic_api_token }}"
--ironic-url="{{ Ironic_api_public_url }}"
node-update "{{ baremetal_uuid }}" add
instance_info/image_source="{{ baremetal_image }}"
instance_info/image_checksum="{{ baremetal_image_checksum }}"
extra/deploy_date="{{ ansible_date_time.iso8601 }}"
extra/deploy_host="{{ ansible_hostname }}"
delegate_to: "{{ groups.client[0] }}"
become: no
run_once: yes
- name: Define the kernel and ramdisk for the image
command: >
ironic
--os-auth-token="{{ Ironic_api_token }}"
--ironic-url="{{ Ironic_api_public_url }}"
node-update "{{ baremetal_uuid }}" add
instance_info/kernel="{{ baremetal_image_kernel }}"
instance_info/ramdisk="{{ baremetal_image_ramdisk }}"
instance_info/root_gb="{{ baremetal_image_rootsize }}"
when: baremetal_image_kernel and baremetal_image_ramdisk
delegate_to: "{{ groups.client[0] }}"
become: no
run_once: yes
- name: Add reference to config-drive in metadata info
command: >
ironic
--os-auth-token="{{ Ironic_api_token }}"
--ironic-url="{{ Ironic_api_public_url }}"
node-update "{{ baremetal_uuid }}" add
instance_info/configdrive="{{ Ironic_configdrive_url }}/{{ baremetal_uuid }}"
when: baremetal_use_configdrive
delegate_to: "{{ groups.client[0] }}"
become: no
run_once: yes
- name: Define configdrive url param
set_fact:
__configdrive: "{{ baremetal_use_configdrive | ternary('--config-drive %s/%s%s' % (Ironic_configdrive_url, baremetal_uuid, configdrive_volume_ext), '') }}"
- name: Active and deploy the server
command: >
ironic
--os-auth-token="{{ Ironic_api_token }}"
--ironic-url="{{ Ironic_api_public_url }}"
node-set-provision-state {{ __configdrive }} "{{ baremetal_uuid }}" active
when: deploy | trim == "y"
delegate_to: "{{ groups.client[0] }}"
become: no
run_once: yes