Provision bare metal with Ansible

This commit is contained in:
Khue Doan 2021-02-07 02:37:41 +07:00
parent b4c0a0b1d1
commit b44b6c0860
8 changed files with 51 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.venv/
target/
*.log

13
metal/Makefile Normal file
View File

@ -0,0 +1,13 @@
.POSIX:
default: init run
init:
python3 -m venv .venv \
&& . .venv/bin/activate \
&& pip3 install --upgrade pip \
&& pip3 install -r requirements.txt
run:
. .venv/bin/activate \
&& ansible-playbook --inventory hosts.ini playbook.yml

5
metal/hosts.ini Normal file
View File

@ -0,0 +1,5 @@
[homelab]
192.168.1.110 mac='00:23:24:d1:f3:f0' ansible_user=root
192.168.1.111 mac='00:23:24:d1:f4:d6' ansible_user=root
192.168.1.112 mac='00:23:24:e7:04:60' ansible_user=root
192.168.1.113 mac='00:23:24:d1:f5:69' ansible_user=root

15
metal/playbook.yml Normal file
View File

@ -0,0 +1,15 @@
- name: Start PXE server on the controller
hosts: localhost
roles:
- { role: pxe, tag: pxe }
- name: Wake all nodes up
hosts: homelab
gather_facts: no
roles:
- { role: wake, tag: wake }
# - name: Shutdown all nodes
# hosts: homelab
# roles:
# - { role: shutdown, tag: shutdown }

3
metal/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
ansible
docker
docker-compose

View File

@ -0,0 +1,3 @@
- name: Start PXE server
community.general.docker_compose:
project_src: /home/khuedoan/Documents/lab/homelab/infra/pxe-server

View File

@ -0,0 +1,3 @@
- name: Unconditionally shut down the machine with all defaults
community.general.shutdown:
delay: 0

View File

@ -0,0 +1,8 @@
- name: Send magic Wake-on-LAN packet
community.general.wakeonlan:
mac: "{{ hostvars[inventory_hostname]['mac'] }}"
delegate_to: localhost
- name: Wait for the servers to comes up
wait_for_connection:
timeout: 600