From df17cc1f2c5995088fdb20ea1607c910ae16fdb6 Mon Sep 17 00:00:00 2001 From: cnbugs Date: Thu, 30 Jul 2026 22:50:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0ipmitool-bmc=20playbo?= =?UTF-8?q?ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playbooks/ipmitool-bmc.yml | 86 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 playbooks/ipmitool-bmc.yml diff --git a/playbooks/ipmitool-bmc.yml b/playbooks/ipmitool-bmc.yml new file mode 100644 index 0000000..1023975 --- /dev/null +++ b/playbooks/ipmitool-bmc.yml @@ -0,0 +1,86 @@ +--- +- name: IPMI配置BMC地址 + hosts: "{{ target_hosts | default('all') }}" + become: yes + vars: + # BMC网络配置 + bmc_ip: "10.10.10.100" + bmc_netmask: "255.255.255.0" + bmc_gateway: "10.10.10.1" + # BMC用户配置 + bmc_user: "admin" + bmc_password: "Admin@123" + bmc_channel: 1 + # 是否启用DHCP(设为true则忽略上面的静态IP配置) + bmc_dhcp: false + + tasks: + - name: 安装ipmitool + package: + name: ipmitool + state: present + + - name: 加载IPMI内核模块 + modprobe: + name: "{{ item }}" + state: present + loop: + - ipmi_devintf + - ipmi_si + ignore_errors: yes + + - name: 查看当前BMC配置 + shell: ipmitool lan print {{ bmc_channel }} + register: bmc_current + changed_when: false + ignore_errors: yes + + - name: 显示当前BMC信息 + debug: + msg: "{{ bmc_current.stdout_lines | default(['无法读取BMC信息']) }}" + + - name: 设置BMC为静态IP + shell: ipmitool lan set {{ bmc_channel }} ipsrc static + when: not bmc_dhcp + + - name: 配置BMC IP地址 + shell: ipmitool lan set {{ bmc_channel }} ipaddr {{ bmc_ip }} + when: not bmc_dhcp + + - name: 配置BMC子网掩码 + shell: ipmitool lan set {{ bmc_channel }} netmask {{ bmc_netmask }} + when: not bmc_dhcp + + - name: 配置BMC默认网关 + shell: ipmitool lan set {{ bmc_channel }} defgw ipaddr {{ bmc_gateway }} + when: not bmc_dhcp + + - name: 设置BMC为DHCP模式 + shell: ipmitool lan set {{ bmc_channel }} ipsrc dhcp + when: bmc_dhcp + + - name: 配置BMC用户密码 + shell: | + ipmitool user set name {{ bmc_channel }} 2 {{ bmc_user }} 2>/dev/null || true + ipmitool user set password 2 {{ bmc_password }} + ipmitool user enable 2 + ipmitool channel setaccess {{ bmc_channel }} 2 privilege=4 + no_log: true + ignore_errors: yes + + - name: 验证BMC配置 + shell: ipmitool lan print {{ bmc_channel }} + register: bmc_verify + changed_when: false + + - name: 显示最终配置 + debug: + msg: | + ═══════ BMC配置完成 ═══════ + 模式: {{ 'DHCP' if bmc_dhcp else '静态IP' }} + IP: {{ bmc_ip }} + 掩码: {{ bmc_netmask }} + 网关: {{ bmc_gateway }} + 用户: {{ bmc_user }} + ═══════════════════════════ + {{ bmc_verify.stdout }}