[Ansible] さくらのVPSにCentOS6を再インストール

Ansibleを使って、さくらのVPSにCentOS6を最小パッケージで再インストールするroleです。

roles/sakura-install/tasks/main.yml

– include: kickstart.yml

roles/sakura-install/tasks/kickstart.yml

– name: Download vmlinuz
 get_url: url=”http://ftp.riken.jp/Linux/centos/6/os/x86_64/isolinux/vmlinuz” dest=/boot
 become: yes
 tags: install

– name: Download initrd.img
 get_url: url=”http://ftp.riken.jp/Linux/centos/6/os/x86_64/isolinux/initrd.img” dest=/boot
 tags: install

– name: Copy Kickstart file
 template: src={{ item.src }} dest={{ item.dst }}
 with_items:
 – src: ks.cfg.j2
 dst: /boot/ks.cfg
 tags: install

– name: Configure grub.conf
 lineinfile:
 dest: /etc/grub.conf
 line: “title CentOS 6 install
    root (hd0,0)
    kernel /vmlinuz ro root=LABEL=/ ks=hd:vda1:/ks.cfg
    initrd /initrd.img”
 tags: install

roles/sakura-install/templates/ks.cfg.j2

firewall –enabled –ssh –service=ssh
# Install OS instead of upgrade
install
# Use network installation
url –url=”http://ftp.riken.jp/Linux/centos/6/os/x86_64″
# Root password
rootpw {{ root_password }}
# System authorization information
auth –useshadow –passalgo=sha512
# Use text mode install
text
# System keyboard
keyboard jp106
# System language
lang en_US
# SELinux configuration
selinux –disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging –level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Tokyo
# Network information
network –bootproto=static –device=eth0 –gateway={{ ansible_default_ipv4.gateway }} –ip={{ ansible_eth0.ipv4.address }} –nameserver={{ nameserver }} –netmask={{ ansible_eth0.ipv4.netmask }} –onboot=on –noipv6 –hostname {{ ansible_nodename }}
# System bootloader configuration
bootloader –append=”console=ttyS0,115200n8r crashkernel=auto” –location=mbr –driveorder=”vda”
# Partition clearing information
clearpart –all –drives=vda
# Disk partitioning information
part /boot –fstype=”ext4″ –size=500
part pv.00 –grow –size=1

volgroup vg_00 –pesize=4096 pv.00
logvol / –fstype=ext4 –name=lv_root –vgname=vg_00 –grow –size=1024 –maxsize=102400
logvol swap –name=lv_swap –vgname=vg_00 –grow –size=512 –maxsize=2048

%packages –nobase
@core

%end

ks.cfg.j2中にroot_passwordを変数で設定していますが、これはvars/main.ymlにべた書きするか、ansible-vaultコマンドで暗号化して保存しておいてください。

このroleを実行後に再起動すれば、自動的に再インストールが始まります。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です