Skip to content

Commit 6da32e1

Browse files
Baremetal instance deployment
1 parent fc278ab commit 6da32e1

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
3+
- name: Update network allocations for new hypervisors
4+
hosts: compute
5+
gather_facts: false
6+
connection: local
7+
serial: 1
8+
vars:
9+
network_allocation_path: "{{ kayobe_env_config_path }}/network-allocation.yml"
10+
tasks:
11+
- name: Show baremetal node
12+
ansible.builtin.shell:
13+
cmd: "openstack baremetal node show {{ inventory_hostname }} -f json"
14+
register: node_show
15+
failed_when: false
16+
changed_when: false
17+
delegate_to: localhost
18+
19+
- name: Set baremetal node JSON variable
20+
ansible.builtin.set_fact:
21+
node_show_json: "{{ node_show.stdout | to_json | from_json }}"
22+
failed_when: false
23+
changed_when: false
24+
25+
- block:
26+
- name: Slurp network allocations
27+
ansible.builtin.slurp:
28+
path: "{{ network_allocation_path }}"
29+
register: net_alc
30+
31+
- name: Read network allocations
32+
ansible.builtin.set_fact:
33+
net_alc_yaml: "{{ net_alc['content'] | b64decode | from_yaml }}"
34+
35+
- name: Write node IP address to allocations
36+
ansible.builtin.set_fact:
37+
new_net_alc: "{{ net_alc_yaml | combine(new_ips, recursive=True) }}"
38+
vars:
39+
new_ips: "{ '{{ admin_oc_net_name }}_ips': { '{{ inventory_hostname }}': '{{ ansible_host }}' } }"
40+
41+
- name: Write new network allocations
42+
ansible.builtin.copy:
43+
content: "{{ new_net_alc | to_nice_yaml(indent=2) }}"
44+
dest: "{{ network_allocation_path }}"
45+
when:
46+
- '"HTTP 404" not in node_show.stderr'
47+
48+
- name: Deploy baremetal compute nodes as hypervisors
49+
hosts: compute
50+
gather_facts: false
51+
connection: local
52+
vars:
53+
hypervisor_image: "37825714-27da-48e0-8887-d609349e703b"
54+
key_name: "testing"
55+
availability_zone: "nova"
56+
baremetal_flavor: "baremetal-A"
57+
baremetal_network: "rack-net"
58+
auth:
59+
auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
60+
username: "{{ lookup('env', 'OS_USERNAME') }}"
61+
password: "{{ lookup('env', 'OS_PASSWORD') }}"
62+
project_name: "{{ lookup('env', 'OS_PROJECT_NAME') }}"
63+
tasks:
64+
- name: Show baremetal node
65+
ansible.builtin.shell:
66+
cmd: "openstack baremetal node show {{ inventory_hostname }} -f json"
67+
register: node_show
68+
failed_when: false
69+
changed_when: false
70+
delegate_to: localhost
71+
72+
- name: Set baremetal node JSON variable
73+
ansible.builtin.set_fact:
74+
node_show_json: "{{ node_show.stdout | to_json | from_json }}"
75+
failed_when: false
76+
changed_when: false
77+
78+
- block:
79+
- name: Create port
80+
openstack.cloud.port:
81+
state: present
82+
name: "{{ inventory_hostname }}"
83+
network: "{{ baremetal_network }}"
84+
auth: "{{ auth }}"
85+
fixed_ips:
86+
- ip_address: "{{ ansible_host }}"
87+
vnic_type: baremetal
88+
delegate_to: localhost
89+
register: port
90+
91+
- name: Deploy hypervisor image
92+
openstack.cloud.server:
93+
state: present
94+
name: "{{ inventory_hostname }}"
95+
nics:
96+
- port-id: "{{ port.port.id }}"
97+
auth: "{{ auth }}"
98+
availability_zone: "{{ availability_zone }}::{{ node_show_json.uuid }}"
99+
image: "{{ hypervisor_image }}"
100+
flavor: "{{ baremetal_flavor }}"
101+
key_name: "{{ key_name }}"
102+
timeout: 1800
103+
config_drive: yes
104+
meta:
105+
ironic_node: "{{ inventory_hostname }}"
106+
delegate_to: localhost
107+
register: server
108+
when:
109+
- '"HTTP 404" not in node_show.stderr'
110+
- '"available" in node_show_json.provision_state'

0 commit comments

Comments
 (0)