style: Ansible lint

This commit is contained in:
Khue Doan 2021-12-26 12:12:36 +07:00
parent 6aa12a1bb9
commit 5de50cd42d
21 changed files with 24 additions and 17 deletions

View File

@ -1,6 +1,6 @@
# Bare-metal
- Ansible renders the configuration file for each bare metal machine (like IP, hostname...) and the PXE server from [templates](./roles/pxe-server/templates)
- Ansible renders the configuration file for each bare metal machine (like IP, hostname...) and the PXE server from [templates](./roles/pxe_server/templates)
- The tools container creates sibling containers to build a PXE server (includes DHCP, TFTP and HTTP server)
- Ansible [wake the machines up](./roles/wake/tasks/main.yml) using Wake on LAN
- The machine start the boot process, the OS get installed (through PXE server) and the machine reboots to the new operating system

View File

@ -1,10 +1,10 @@
- name: Start PXE server
hosts: localhost
roles:
- pxe-server
- pxe_server
- name: Provision bare metal machines
hosts: metal
gather_facts: no
gather_facts: false
roles:
- wake

View File

@ -1,11 +1,11 @@
k3s_version: v1.23.1-rc1+k3s1 # TODO switch to stable
k3s_version: v1.23.1-rc1+k3s1 # TODO switch to stable
k3s_config_file: /etc/rancher/k3s/config.yaml
k3s_token_file: /etc/rancher/node/password
k3s_service_file: /etc/systemd/system/k3s.service
k3s_server_config:
disable:
- local-storage
- servicelb
- traefik
- local-storage
- servicelb
- traefik
disable-cloud-controller: true
secrets-encryption: true

View File

@ -19,25 +19,27 @@
file:
path: "{{ item }}"
state: directory
mode: 0755
loop:
- /etc/rancher/k3s
- /etc/rancher/node
- name: Check if k3s token file exists on the first node
run_once: yes
run_once: true
stat:
path: "{{ k3s_token_file }}"
register: k3s_token_file_stat
- name: Generate k3s token file on the first node if not exist yet
run_once: yes
run_once: true
when: not k3s_token_file_stat.stat.exists
copy:
content: "{{ lookup('community.general.random_string', length=32) }}"
dest: "{{ k3s_token_file }}"
mode: 0600
- name: Get k3s token from the first node
run_once: yes
run_once: true
slurp:
src: "{{ k3s_token_file }}"
register: k3s_token_base64
@ -46,11 +48,13 @@
copy:
content: "{{ k3s_token_base64.content | b64decode }}"
dest: "{{ k3s_token_file }}"
mode: 0600
- name: Copy k3s config files
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: 0644
loop:
- src: config.yaml.j2
dest: "{{ k3s_config_file }}"
@ -60,14 +64,14 @@
- name: Enable k3s service
systemd:
name: k3s
enabled: yes
enabled: true
state: started
register: k3s_service
until: k3s_service is succeeded
retries: 5
- name: Get Kubernetes config file
run_once: yes
run_once: true
slurp:
src: /etc/rancher/k3s/k3s.yaml
register: kubeconfig_base64

View File

@ -14,21 +14,24 @@
template:
src: dhcpd.conf.j2
dest: "{{ role_path }}/files/data/pxe-config/dhcpd.conf"
mode: 0644
- name: Render GRUB config
template:
src: grub.cfg.j2
dest: "{{ role_path }}/files/data/pxe-config/grub.cfg"
mode: 0644
- name: Render machine specific init config
template:
src: kickstart.ks.j2
dest: "{{ role_path }}/files/data/init-config/{{ hostvars[item]['mac'] }}.ks"
mode: 0644
loop: "{{ groups['metal'] }}"
- name: Start ephemeral PXE server
docker_compose:
project_src: "{{ role_path }}/files"
state: present
restarted: yes
build: yes
restarted: true
build: true

View File

@ -1,11 +1,11 @@
- name: Shutdown the homelab
hosts: metal
gather_facts: no
gather_facts: false
tasks:
- name: Unconditionally shut down the machine
community.general.shutdown:
delay: 0
ignore_unreachable: yes
ignore_unreachable: true
- name: Wait for the machine to shutdown
shell: "until ! ping -c 1 {{ ansible_host }}; do sleep 1; done"
delegate_to: localhost

View File

@ -1,3 +1,3 @@
#!/bin/sh
docker compose --project-directory ./metal/roles/pxe-server/files/ logs --follow
docker compose --project-directory ./metal/roles/pxe_server/files/ logs --follow