涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  428 随笔 :: 0 文章 :: 19 评论 :: 22万 阅读

https://gist.github.com/wrunk/1317933

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from jinja2 import Environment, FileSystemLoader
import os

if __name__ == '__main__':
    j2_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'jinja2')
    kickstart_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'kickstart')
    pxe_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pxe')

    j2_env = Environment(loader=FileSystemLoader(j2_path))

    host = {
        'root_password': '123456',
        'os': 'centos-6',
        'install_host': 'install.localhost',
        'name': 'bjtn-g18-10-11',
        'interface': [
            {'dev': 'em1', 'mac': 'aa:aa:aa:aa:aa:01', 'ip': '10.0.10.11', 'mask': '255.255.255.0'},
            {'dev': 'em2', 'mac': 'aa:aa:aa:aa:aa:02', 'ip': '200.0.10.11', 'mask': '255.255.255.192'}
        ],
       'gateway': '10.0.10.1'
    }
    
    with open(os.path.join(kickstart_path, host['interface'][0]['mac']), 'w') as f:
        f.write(j2_env.get_template('ks-centos-6').render(host=host))

    with open(os.path.join(pxe_path, host['interface'][0]['mac']), 'w') as f:
        f.write(j2_env.get_template('pxe-centos-6').render(host=host))

pxe-centos-6

LABEL {{ os }}
    MENU DEFAULT
    MENU LABEL {{ mac }}
    KERNEL {{ os }}/vmlinuz
    APPEND initrd={{ os }}/initrd.img ks=http://{{ install_host }}/kickstart/{{ mac }} ksdevice=link ramdisk_size=102400 console=tty0 console=ttyS1,115200

ks-centos-6

# kickstart
lang en_US.UTF-8
keyboard us
timezone Asia/Shanghai

auth --enableshadow --passalgo=sha512
#python -c 'import crypt; print(crypt.crypt("MyPassword", "$6$MySalt"))'
rootpw --iscrypted {{ host.root_password }}
text
install
skipx
url --url http://{{ host.install_host }}/{{ host.os }}

bootloader --location=mbr 
zerombr
clearpart --drives=sda --all #--initlabel 

part swap --fstype='swap' --ondisk=sda --size=8000
part / --fstype='ext4' --ondisk=sda --size=50000
part /opt --fstype='ext4' --ondisk=sda --grow --size=1

network --device={{ host.interface[0].mac }} --bootproto=dhcp --activate

firewall --disabled
selinux --disabled
services --disabled=NetworkManager,ip6tables,iptables,postfix,cpuspeed
services --enabled=network
firstboot --disabled
reboot

%packages
@Base
wget
%end

%pre
clearpart --drives=sda --all
/usr/sbin/parted -s /dev/sda mklabel gpt
%end

%post
cat > /etc/sysconfig/network << _EOF_
NETWORKING=yes
HOSTNAME={{ host.name }}
GATEWAY={{ host.gateway }}
_EOF_

{% for nic in host.interface %}
cat > /etc/sysconfig/network-scripts/ifcfg-{{ nic.dev }} << _EOF_
BOOTPROTO=static
DEVICE={{ nic.dev }}
IPADDR={{ nic.ip }}
NETMASK={{ nic.mask }}
ONBOOT=yes
_EOF_
{% endfor %}
%end
posted on   北京涛子  阅读(1655)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
历史上的今天:
2015-04-07 vim配置
2015-04-07 ubuntu & sublime字体设置
点击右上角即可分享
微信分享提示