From 25de291c713ac553d7a7a038efe41b5cd62b9702 Mon Sep 17 00:00:00 2001 From: Khue Doan Date: Mon, 30 Aug 2021 23:47:16 +0700 Subject: [PATCH] Split init config to a separate role --- metal/roles/init-config/defaults/main.yml | 1 + metal/roles/init-config/tasks/main.yml | 4 ++ .../roles/init-config/templates/kickstart.ks | 49 +++++++++++++++++++ metal/roles/pxe-server/tasks/main.yml | 22 --------- 4 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 metal/roles/init-config/defaults/main.yml create mode 100644 metal/roles/init-config/tasks/main.yml create mode 100644 metal/roles/init-config/templates/kickstart.ks diff --git a/metal/roles/init-config/defaults/main.yml b/metal/roles/init-config/defaults/main.yml new file mode 100644 index 00000000..0e57f1d3 --- /dev/null +++ b/metal/roles/init-config/defaults/main.yml @@ -0,0 +1 @@ +timezone: Asia/Ho_Chi_Minh diff --git a/metal/roles/init-config/tasks/main.yml b/metal/roles/init-config/tasks/main.yml new file mode 100644 index 00000000..1ed4ef1f --- /dev/null +++ b/metal/roles/init-config/tasks/main.yml @@ -0,0 +1,4 @@ +- name: Render machine specific init config + template: + src: kickstart.ks.j2 + dest: "{{ playbook_dir }}/build/data/init-config/{{ hostvars[item]['mac'] }}.ks" diff --git a/metal/roles/init-config/templates/kickstart.ks b/metal/roles/init-config/templates/kickstart.ks new file mode 100644 index 00000000..ffe6351c --- /dev/null +++ b/metal/roles/init-config/templates/kickstart.ks @@ -0,0 +1,49 @@ +#version=DEVEL + +# Do not use graphical install +text + +# Keyboard layouts +keyboard --xlayouts='us' +# System language +lang en_US.UTF-8 + +# Partition clearing information +clearpart --all --drives={{ disk }} +# Partitioning +ignoredisk --only-use={{ disk }} +autopart + +# Network information +network --bootproto=static --device={{ network_interface }} --ip={{ hostvars[item]['ansible_host'] }} --gateway={{ ansible_default_ipv4.gateway }} --nameserver={{ dns_server }} --netmask={{ ansible_default_ipv4.netmask }} --ipv6=auto --hostname={{ hostvars[item]['inventory_hostname'] }} --activate + +# Use network installation +url --url="http://{{ ansible_default_ipv4.address }}/iso/" +# Disable Setup Agent on first boot +firstboot --disable +# Do not configure the X Window System +skipx +# System services +services --enabled="chronyd" +# System timezone +timezone {{ timezone }} --utc + +# Create user (locked by default) +user --groups=wheel --name={{ os_username }} +# Add SSH key +sshkey --username=root "{{ ssh_public_key }}" + +# SELinux +selinux --disabled + +# Firewall +firewall --disabled + +%packages +@^server-product-environment +%end + +# Enable some services for Kubernetes +services --enable=iscsid + +reboot diff --git a/metal/roles/pxe-server/tasks/main.yml b/metal/roles/pxe-server/tasks/main.yml index bb0f7684..dafe9175 100644 --- a/metal/roles/pxe-server/tasks/main.yml +++ b/metal/roles/pxe-server/tasks/main.yml @@ -46,28 +46,6 @@ src: tftp/tftpboot/grub.cfg.j2 dest: "{{ role_path }}/build/tftp/tftpboot/grub.cfg" -- name: Render machine specific Butane config - template: - src: http/ignition/ignition.yaml.j2 - dest: "{{ role_path }}/build/http/ignition/{{ hostvars[item]['mac'] }}.yaml" - loop: "{{ groups['metal'] }}" - -- name: Render Ignition config from Butane config - docker_container: - name: butane - image: quay.io/coreos/butane:release - auto_remove: yes - volumes: - - "{{ role_path }}/build/http/ignition:/local/src" - working_dir: /local/src - command: - - --pretty - - --strict - - "{{ hostvars[item]['mac'] }}.yaml" - - --output - - "{{ hostvars[item]['mac'] }}.json" - loop: "{{ groups['metal'] }}" - - name: Start ephemeral PXE server docker_compose: project_src: "{{ role_path }}/build"