LoginSignup
4
4

More than 3 years have passed since last update.

CentOS 8 をkickstartでinstall、Ansibleが使えるまで

Last updated at Posted at 2019-11-05

anaconda-ks.cfg の準備

まずCentOS8を最小インストールでインストールしログイン。
/root/anaconda-ks.cfgがインストール時に選択した設定なので手元にscpなどでコピーしておく。

anaconda-ks.cfgを編集し、次回からのOSインストールを楽にする。

修正

今回はkickstartに以下の内容を追加した。

  • /サイズを自動で空き容量最大まで指定
  • SELinuxの無効化
  • Ansibleのインストール
  • Firewallの無効化
anaconda-ks.cfg
part / --fstype="ext4" --ondisk=vda --size=1 --grow

()

%post --log=/root/ks-post-anaconda.log
set -x
# SELinux
sed -i -e "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# Ansible
yum install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm"
yum install --enablerepo epel-playground -y ansible
# firewalld
systemctl disable firewalld
%end

手順

ブート画面

  • CentOS8のisoでブートしたら以下の画面となる。
    • ESCキーを押下。

ks1.png

linux ks= の指定

  • linux ks=http://192.168.xx.xx/anaconda-ks.cfg を指定
    • ファイル名は変更してもよい。キー配列がusなため、=:の入力には注意
    • (CentOSのバージョンによってはlinux ksだけで途中までブート出来たがCentOS8は指定する必要がある。)

ks2.png

待つ

done.png

Ansible

以下3つのファイルを用意。

  • run.sh
  • site.yml
  • vars/packages.yml
run.sh
#!/bin/sh

ansible-playbook --ask-become-pass -c local site.yml
site.yml
- hosts: localhost
  become: yes
  gather_facts: no
  vars_files:
    - "vars/packages.yml"
  tasks:
    - name: ensure a list of packages installed
      dnf: name="{{ packages }}" state=installed
vars/packages.yml
---
packages:
  - git
  - wget
  - tar
実行
sh run.sh
# sudo のパスワードが求められる。
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4