Skip to content

Commit

Permalink
Baremetal instance deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
assumptionsandg committed Jun 6, 2024
1 parent fc278ab commit e2e2213
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions etc/kayobe/ansible/deploy-baremetal-instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---

- name: Update network allocations for new hypervisors
hosts: compute
gather_facts: false
connection: local
serial: 1
vars:
network_allocation_path: "{{ lookup('env', 'KAYOBE_CONFIG_PATH') }}/environments/{{ lookup('env', 'KAYOBE_ENVIRONMENT') }}/network-allocation.yml"
tasks:
- name: Show baremetal node
ansible.builtin.shell:
cmd: "openstack baremetal node show {{ inventory_hostname }} -f json"
register: node_show
failed_when: false
changed_when: false
delegate_to: localhost

- name: Set baremetal node JSON variable
ansible.builtin.set_fact:
node_show_json: "{{ node_show.stdout | to_json | from_json }}"
failed_when: false
changed_when: false

- block:
- name: Slurp network allocations
ansible.builtin.slurp:
path: "{{ network_allocation_path }}"
register: net_alc

- name: Read network allocations
ansible.builtin.set_fact:
net_alc_yaml: "{{ net_alc['content'] | b64decode | from_yaml }}"

- name: Write node IP address to allocations
ansible.builtin.set_fact:
new_net_alc: "{{ net_alc_yaml | combine(new_ips, recursive=True) }}"
vars:
new_ips: "{ '{{ admin_oc_net_name }}_ips': { '{{ inventory_hostname }}': '{{ ansible_host }}' } }"

- name: Write new network allocations
ansible.builtin.copy:
content: "{{ new_net_alc | to_nice_yaml(indent=2) }}"
dest: "{{ network_allocation_path }}"
when:
- '"HTTP 404" not in node_show.stderr'

- name: Deploy baremetal compute nodes as hypervisors
hosts: compute
gather_facts: false
connection: local
vars:
hypervisor_image: "37825714-27da-48e0-8887-d609349e703b" # Rocky-8-GenericCloud-Base-8.9-20231119
key_name: "testing"
availability_zone: "nova"
baremetal_flavor: "baremetal-A"
baremetal_network: "rack-net"
auth:
auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
username: "{{ lookup('env', 'OS_USERNAME') }}"
password: "{{ lookup('env', 'OS_PASSWORD') }}"
project_name: "{{ lookup('env', 'OS_PROJECT_NAME') }}"
tasks:
- name: Show baremetal node
ansible.builtin.shell:
cmd: "openstack baremetal node show {{ inventory_hostname }} -f json"
register: node_show
failed_when: false
changed_when: false
delegate_to: localhost

- name: Set baremetal node JSON variable
ansible.builtin.set_fact:
node_show_json: "{{ node_show.stdout | to_json | from_json }}"
failed_when: false
changed_when: false

- block:
- name: Create port
openstack.cloud.port:
state: present
name: "{{ inventory_hostname }}"
network: "{{ baremetal_network }}"
auth: "{{ auth }}"
fixed_ips:
- ip_address: "{{ ansible_host }}"
vnic_type: baremetal
delegate_to: localhost
register: port

- name: Deploy Rocky on hypervisor
openstack.cloud.server:
state: present
name: "{{ inventory_hostname }}"
nics:
- port-id: "{{ port.port.id }}"
auth: "{{ auth }}"
availability_zone: "{{ availability_zone }}::{{ node_show_json.uuid }}"
image: "{{ hypervisor_image }}"
flavor: "{{ baremetal_flavor }}"
key_name: "{{ key_name }}"
timeout: 1800
config_drive: yes
meta:
ironic_node: "{{ inventory_hostname }}"
delegate_to: localhost
register: server
when:
- '"HTTP 404" not in node_show.stderr'
- '"available" in node_show_json.provision_state'

0 comments on commit e2e2213

Please sign in to comment.