本稿の構成
タイトル | 内容 | コメント |
---|---|---|
Cisco Nexus を Puppet で設定する1 | Puppet Master のインストール | 元ネタ:Installing Puppet: Linux |
Cisco Nexus を Puppet で設定する2a | Puppet Agent のインストール・Bash編 | 元ネタ:Puppet Agent Installation & Setup: Cisco Nexus |
Cisco Nexus を Puppet で設定する2b | Puppet Agent のインストール・guestshell編 | 未完成 |
Cisco Nexus を Puppet で設定する3 | puppetlabs-ciscopuppet モジュールのインストール | 元ネタ:cisco-network-puppet-module: Example Manifest Usage |
はじめに
※当初 Guestshell を使う方法で進めましたが問題に遭遇(puppetlabs-ciscopuppet モジュールをインストールしても正しく動作しない)したため bash を使う方法に記述を変更しています
事前準備:Nexus3048 へ Puppet Agent をインストールする前に
Nexus3048 のバージョンアップ
7.0(3)I2(1) から NX-OS のバージョンアップ方法が変更された。Open Bootloader と呼ばれる手法が採用され主な変更点は以下の通り([詳細]
(http://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus3000/sw/release/70321/n3k_70321_nxos_rn.html)):
- 従来 NX-OS には system (ファイル名の例:n3000-uk9.6.0.2.U6.5.bin) と kickstart 2つのイメージが存在したが、新手法では nx-os (ファイル名の例:nxos.7.0.3.I2.2a.bin) と言う名のイメージ1つへ集約された
- バージョンアップのためのコマンドも変更された。例:install all nxos bootflash:nxos.7.0.3.I2.1.bin
※注意点
6.0(2)U6(2) 以前のバージョンから 7.0(3)I2(1) 以降へいきなりバージョンアップしようとすると以下のエラーメッセージが出て失敗する(詳細)。
switch# install all nxos bootflash:nxos.7.0.3.I2.2a.bin
Installer is forced disruptive
Verifying image bootflash:/nxos.7.0.3.I2.2a.bin for boot variable "nxos".
[########################################] 100% -- SUCCESS
Verifying image type.
[########################################] 100% -- SUCCESS
Extracting "nxos" version from image bootflash:/nxos.7.0.3.I2.2a.bin.
[########################################] 100% -- SUCCESS
Extracting "bios" version from image bootflash:/nxos.7.0.3.I2.2a.bin.
[########################################] 100% -- SUCCESS
Pre-upgrade check failed. Return code 0x40930053 (failed to collection plugin information).
対応策は一度 6.0(2)U6(3) へバージョンアップした後に 7.0(3)I2(1) へ上げればよい。
switch# install all system bootflash:n3000-uk9.6.0.2.U6.3.bin kickstart bootflash:n3000-uk9-kickstart.6.0.2.U6.3.bin
以下はうまくいった場合のログ(6.0(2)U6(3) → 7.0(3)I2(2a) )
switch# install all nxos nxos.7.0.3.I2.2a.bin
Installer is forced disruptive
Verifying image bootflash:/nxos.7.0.3.I2.2a.bin for boot variable "nxos".
[########################################] 100% -- SUCCESS
Verifying image type.
[########################################] 100% -- SUCCESS
Extracting "nxos" version from image bootflash:/nxos.7.0.3.I2.2a.bin.
[########################################] 100% -- SUCCESS
Extracting "bios" version from image bootflash:/nxos.7.0.3.I2.2a.bin.
[########################################] 100% -- SUCCESS
Performing runtime checks.
[########################################] 100% -- SUCCESS
Performing module support checks.
[########################################] 100% -- SUCCESS
Notifying services about system upgrade.
[########################################] 100% -- SUCCESS
Compatibility check is done:
Module bootable Impact Install-type Reason
------ -------- -------------- ------------ ------
1 yes disruptive reset Unsupported in new image, module needs to be powered off
Images will be upgraded according to following table:
Module Image Running-Version New-Version Upg-Required
------ ---------------- ---------------------- ---------------------- ------------
1 kickstart 6.0(2)U6(3) 7.0(3)I2(2a) yes
1 bios v1.2.0(08/25/2011) v3.4.0(08/07/2015) yes
Switch will be reloaded for disruptive upgrade.
Do you want to continue with the installation (y/n)? [n] y
NX-OS ネットワーク設定
今回使用する Nexus3048 は以下の形:
Nexus3048 (mgmt interface) ------ L2 スイッチ ----- コンソール用PC
※ インストールにはインターネットへのアクセスが必要。上記構成図ではL2スイッチ経由でインターネットに接続されている想定。Nexus3048 の mgmt interface (int mgmt0) 経由で接続を行っており、通常 mgmt0 は management という名の VRF に所属させるが、Bash に入った場合も VRF の切り替えが必要(managemtn VRF へ切り替える には ip netns exec management bash)
NX-OS ネットワーク設定例は以下:
switch# config term
switch(config)# ntp server 10.0.0.201 use-vrf management
switch(config)# vrf context management
switch(config)# ip name-server 10.0.0.202
switch(config)# ip domain-name mycompany.com
switch(config)# ip route 0.0.0.0/0 10.0.0.1
switch(config)# interface mgmt0
switch(config-if)# vrf member management
switch(config-if)# ip address 10.0.0.99/24
switch(config-if)# end
設定方法の選択(bash-shell or guestshell)
Puppet を Nexus3048 のどこにインストールするか?
NX-OS は実は Linux 上で動いており、そのネイティブの bash を使ってインストールする方法と、Linux コンテナ内の guestshell を使ってインストールする方法の二通りが存在する。今回は Bash-shell にて設定を行う。
Puppet Agent のインストールと設定(Bash-shell編)
基本設定
switch# configure terminal
switch(config)# feature bash-shell
switch(config)# hostname n3k
n3k# run bash
bash-4.2$
bash-4.2$ sudo su -
root@n3k# ip netns exec management bash
root@n3k# cat >> /etc/resolv.conf << EOF
nameserver 10.0.0.202
domain mycompany.com
search mycompany.com
EOF
ip netns exec management bash は VRF を VRF名= management へ変更するコマンド。
NX-OS の bash は独自のクセがあり、Linux のファイルシステムへの変更しても再起動すると元に戻ってしまう。今回は /etc/resolv.conf への変更をしているがこれを再起動後も有効にしたい場合は NX-OS のシェルに戻って copy running-config startup-config をするか、または bash シェルから以下を実行する:
# vsh -c 'copy running-config startup-config'
Proxy 設定(オプション)
proxy 経由でインターネットへ接続する場合は proxy の設定を行う:
# vi /etc/profile
PROXY='proxy.server.com'
export http_proxy=$PROXY
export HTTP_PROXY=$PROXY
export HTTPS_PROXY=$PROXY
export https_proxy=$PROXY
変更を反映させる:
# source /etc/profile
proxy 経由でインターネットへ接続する場合は yum についても proxy の設定を行う:
# vi /etc/yum.conf
proxy=http://proxy.server.com:8080
Puppet Agent RPM のインストール
以下の2行を実施すればよい:
# yum install http://yum.puppetlabs.com/puppetlabs-release-pc1-cisco-wrlinux-5.noarch.rpm
# yum install puppet
ところが、1行目実行後
Setting up Install Process
puppetlabs-release-pc1-cisco-wrlinux-5.noarch.rpm | 5.8 kB 00:00
warning: rpmts_HdrFromFdno: Header V4 RSA/SHA512 signature: NOKEY, key ID 4bd6ec30
Cannot open: http://yum.puppetlabs.com/puppetlabs-release-pc1-cisco-wrlinux-5.noarch.rpm. Skipping.
Error: Nothing to do
で止まってしまった。これは以下で解決できた。
ネットワーク接続に問題がないことを確認する:
# wget http://yum.puppetlabs.com/puppetlabs-release-pc1-cisco-wrlinux-5.noarch.rpm
GPG-key をインストールする:
# rpm --import http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
# rpm --import http://yum.puppetlabs.com/RPM-GPG-KEY-reductive
以上で問題が解決し、上記二行の yum install が実行可能となる。
※ Nexus9000 7.0(3)I4(1) には rpm に問題があるらしく yum install 時に以下のようなエラーが出る:
sed: can't read /bootflash/.rpmstore/thirdparty/inactive_feature_rpms.inf: No such file or directory
2016/7/19 時点ではこの問題を解決した 7.0(3)I2(2e) が推奨
PATH の Update
# export PATH=/opt/puppetlabs/puppet/bin:/opt/puppetlabs/puppet/lib:$PATH
cisco_node_utils gem のインストール
Puppet は cisco_node_utils gem を使うので必ず Agent へインストールする必要がある。
# /opt/puppetlabs/puppet/bin/gem install cisco_node_utils
成功すると cisco_node_utils, cisco_nxapi, net_http_unix の 3つの gem がインストールされる。確認は gem list で可能:
# /opt/puppetlabs/puppet/bin/gem list | egrep 'cisco|net_http'
cisco_node_utils (1.2.0)
cisco_nxapi (1.0.1)
net_http_unix (0.2.1)
gem インストールについての補足
Guestshell の場合 gem は一度インストールすれば完了。
NX-OS bash-shell の場合、/opt/puppetlabs にインストールしたファイルは再起動で消えてしまうので、再起動の都度インストールする必要があるが、いちいち手作業でするのは面倒なので、マニフェストの最初に include ciscopuppet::install を記述すれば自動で最新の gem をインストールしてくれる。マニフェストの具体例は こちら 参照。
Puppet 設定ファイルを修正
vi /etc/puppetlabs/puppet/puppet.conf
[main]
server = sevtdc001.localdomain
[agent]
pluginsync = true
ignorecache = true
init.d を変更
# cp /etc/init.d/puppet /etc/init.d/puppet.old
# vi /etc/init.d/puppet
#daemon $daemonopts $puppetd ${PUPPET_OPTS} ${PUPPET_EXTRA_OPTS}
daemon $daemonopts ip netns exec management $puppetd ${PUPPET_OPTS} ${PUPPETT
_EXTRA_OPTS}
puppet service を起動:
# chkconfig --add puppet
# chkconfig --level 345 puppet on
# service puppet start
puppet Agent の実行
puppet agent -t コマンドにて Puppet Agent を実行可能。現在 Puppet Master にはマニフェストファイルを置いていないため、同コマンドを実行すると Puppet Master との接続性確認のみが行われる。接続には証明書が利用される。試しに実行してみると:
# puppet agent -t
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppetlabs/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for n3k.mycompany.com
Info: Certificate Request fingerprint (SHA256):
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled
とエラーが表示されるがこれは期待された動作であり、Puppet Agent を Puppet Master に登録していないため。試しに Puppet Master にて証明書の一覧を表示してみる:
# puppet cert list --all
"n3k.cisco.com" (SHA256) x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x
+ "localhost.localdomain" (SHA256) x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x:x (alt names: "DNS:puppet", "DNS:localhost.localdomain"
上記出力例のように該当 Puppet Agent の頭に + がついていない場合は Agent の証明書に署名されていない。そこで Puppet Master 側で登録を行う:
# puppet cert sign --all
再度 Puppet Agent にて puppet agent -t を実行:
# puppet agent -t
Info: Caching certificate_revocation_list for ca
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for n3k.mycompany.com
Info: Applying configuration version '1452153556'
Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml
Notice: Applied catalog in 0.02 seconds
無事処理が完了した。