0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AnsibleでESXi上の仮想マシンに vCSAインストール用のNTP&DNSサーバを立てる

Posted at

vCSAのインストールにはNTPとDNSが必要なため(NTPは一応必須ではないですが)、ESXi上の仮想マシンにNTPとDNSを立てる。
(とりあえず動けばいいで作ったので検証用です)

コントロールノード環境

※Windows10上のvagrant上
クライアントOS: CentOS Linux release 7.6.1810 (Core)
Ansibleのversion: 2.9.1

ターゲットノード環境

ESXi: 6.7
VMのOS: CentOS Linux release 7.7.1908 (Core)

こちらの記事を参照すると vsphere_guestモジュールをAnsibleで使用すればvCenterがない環境でもESXiでも使用できるぽいですが、Ansible2.9で削除されているらしいので今回は使用しません。VMのOSはkickstartを使用してOSレベルでのインストールは自動化しています。

ファイル構成

ansible
├── ansible.cfg
├── contents
│   ├── dnsmasq.conf
│   ├── hosts
│   └── resolv.conf
├── inventory
└── testvm.yml

プレイブック

testvm.yml
---
- hosts: VMserver
  gather_facts: false                                   
  tasks: 
   - name: set hostname
     hostname: 
       name: vmtest.local.com    

  #必要なパッケージをインストール                        
   - name: upgrade all packages
     yum: 
      name: '*'
      state: latest

   - name: install the openvm-tools
     yum: 
      name: open-vm-tools 
      state: latest

   - name: install the dnsmasq
     yum: 
      name: dnsmasq 
      state: latest

   - name: install the dnsmasq
     yum: 
      name: bind-utils 
      state: latest

   - name: install the ntpd
     yum: 
      name: ntp
      state: latest
  
  #dnsmasqの設定をファイルを置き換えて、起動させる。
   - name: Copy dnsmasqcon
     copy:
        src:  ./contents/dnsmasq.conf
        dest: /etc/dnsmasq.conf
        owner: root
   - name: Copy hosts
     copy:
        src:  ./contents/hosts
        dest: /etc/hosts
        owner: root
   - name: Copy resolv.conf
     copy:
        src:  ./contents/resolv.conf
        dest: /etc/resolv.conf
        owner: root
   - name: start dnsmasq
     systemd:
        state: started
        name: dnsmasq
  #ntpdの設定ファイルを置き換えて起動させる
   - name: start ntpd
     systemd:
        state: started
        name: ntpd

contents

※置き換える設定ファイル

dnsmasq.conf
※デフォルトの設定ファイルが非常に長いので別サーバでyum install dnsmasqして作成される/etc/dnsmasq.confをコピーして作成
最終的にコメント以下の設定がdnsmasq.confがコメントアウトされていればOK

[root@testvm ~]# cat /etc/dnsmasq.conf | grep -v "^#" | grep -v "^$"
domain-needed
bogus-priv
strict-order
local=/local.com/
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig

設定値の参考にしたサイト

resolv.conf
nameserver 127.0.0.1
nameserver 8.8.8.8
hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
"vCSAのデプロイ予定のIP" vcsa.local.com server01
“VMサーバのIP” testvm.local.com dns-server

インベントリ

inventory

[VMserver]
”ESXi上の仮想サーバのIP”

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=password
ansible_sudo_pass=password

ansible.cfg

以下の設定を追記

[defaults]
host_key_checking = False

コマンド実行

ansibleディレクトリで実行する

# ansible-playbook -i inventory testvm.yml
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?