Linux版PowerCLIのインストール
はじめに
スズケンです。久々の投稿です。
今回は、Linux版PowerCLIのインストールについて書きたいと思います。
■前提
今回は、会社環境でよくありがちな、インターネットにつながっていない環境でのLinux版PowerCLIを想定して、インストール方法を試行錯誤してみました。
■Powershellのインストール
まずは、Powershellを入れてみます。 インターネットにつながる環境で、下記サイトからrpmをダウンロードします。
https://packages.microsoft.com/rhel/7/prod/
[root@localhost ~]# rpm -ivh powershell-lts-7.0.3-1.rhel.7.x86_64.rpm [root@localhost ~]# rpm -qa | grep powershell powershell-lts-7.0.3-1.rhel.7.x86_64
※ltsが付くパッケージ名のものは、rpmインストール時にダウンロード不要なもののようです。
■Powershellの起動
Powershellを起動できました。
[root@localhost ~]# pwsh PowerShell 7.0.3 Copyright (c) Microsoft Corporation. All rights reserved. https://aka.ms/powershell Type 'help' to get help. PS /root>
利用可能なモジュールを確認してみます。
PS /root> Get-Module -ListAvailable Directory: /opt/microsoft/powershell/7-lts/Modules ModuleType Version PreRelease Name PSEdition ---------- ------- ---------- ---- --------- Manifest 1.2.5 Microsoft.PowerShell.Archive Desk Manifest 7.0.0.0 Microsoft.PowerShell.Host Core Manifest 7.0.0.0 Microsoft.PowerShell.Management Core Manifest 7.0.0.0 Microsoft.PowerShell.Security Core Manifest 7.0.0.0 Microsoft.PowerShell.Utility Core Script 1.4.7 PackageManagement Desk Script 2.2.4.1 PowerShellGet Desk Script 2.0.5 PSDesiredStateConfiguration Core Script 2.0.2 PSReadLine Desk Binary 2.0.3 ThreadJob Desk
■PowerCLIのインストール準備
インターネットにつながらない環境でのPowerCLIのインストールをするとなると、通常のInstall-Moludeコマンドは使えません。 まずは、インターネットにつながる環境で、PowerCLIのモジュールを入手すべく、Save-ModuleコマンドでPowerCLIのモジュールをダウンロードします。
ダウンロード先のディレクトリを作成します。
PS /root> mkdir powershell
PowerCLI用のモジュールファイルをダウンロードします。
PS /root> Save-Module -Name VMware.PowerCLI -Path ./powershell/
tar.gzファイルに固めます。
PS /root> cd ./powershell/ PS /root/powershell> ls -l 0 drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.CloudServices drwxr-xr-x. 3 root root 28 10 24 21:35 VMware.DeployAutomation drwxr-xr-x. 3 root root 28 10 24 21:35 VMware.ImageBuilder drwxr-xr-x. 3 root root 29 10 24 21:35 VMware.PowerCLI drwxr-xr-x. 3 root root 28 10 24 21:34 VMware.Vim drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Cis.Core drwxr-xr-x. 3 root root 29 10 24 21:35 VMware.VimAutomation.Cloud drwxr-xr-x. 3 root root 29 10 24 21:33 VMware.VimAutomation.Common drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Core drwxr-xr-x. 3 root root 29 10 24 21:35 VMware.VimAutomation.Hcx drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.HorizonView drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.License drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Nsxt drwxr-xr-x. 3 root root 29 10 24 21:33 VMware.VimAutomation.Sdk drwxr-xr-x. 3 root root 29 10 24 21:35 VMware.VimAutomation.Security drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Srm drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Storage drwxr-xr-x. 3 root root 21 10 24 21:35 VMware.VimAutomation.StorageUtility drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Vds drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.Vmc drwxr-xr-x. 3 root root 29 10 24 21:35 VMware.VimAutomation.WorkloadManagement drwxr-xr-x. 3 root root 29 10 24 21:34 VMware.VimAutomation.vROps drwxr-xr-x. 3 root root 29 10 24 21:35 VMware.VumAutomation
tarファイルで固めます。
PS /root/powershell> tar cf powercli.tar ./VMware.* PS /root/powershell> gzip ./powercli.tar PS /root/powershell> ls -l ./powercli.tar.gz -rw-r--r--. 1 root root 67183865 10月 24 22:49 ./powercli.tar.gz
■PowerCLIのインストール(モジュールの配置)
tar.gzファイルをインストールしたい環境に持ってきます(ここの手順は脳内で補完してください)。
持ってきたファイルを展開する場所は、下記コマンドのパスのうち、/usr/local/share/powershell/Modules に置くことにします。
PS /root> $Env:PSModulePath /root/.local/share/powershell/Modules:/usr/local/share/powershell/Modules:/opt/microsoft/powershell/7/Modules
持ってきたファイルを展開します。
PS /root> mkdir /usr/local/share/powershell/Modules PS /root> PS /root> cd /usr/local/share/powershell/Modules PS /usr/local/share/powershell/Modules> PS /usr/local/share/powershell/Modules> ls -l ./powercli.tar.gz -rw-r--r--. 1 root root 67183865 10月 24 22:49 ./powercli.tar.gz PS /usr/local/share/powershell/Modules> PS /usr/local/share/powershell/Modules> gunzip ./powercli.tar.gz PS /usr/local/share/powershell/Modules> PS /usr/local/share/powershell/Modules> ls -l ./powercli.tar -rw-r--r--. 1 root root 350105600 10月 24 22:49 ./powercli.tar PS /usr/local/share/powershell/Modules> PS /usr/local/share/powershell/Modules> tar xf ./powercli.tar
あと、おまじないで下記を実行します。
PS /usr/local/share/powershell/Modules> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore Perform operation? Performing operation 'Update PowerCLI configuration.'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayD eprecati onWarnin gs ----- ----------- ------------------- ------------------------ -------- Session UseSystemProxy Multiple Ignore True User Ignore AllUsers
PS /usr/local/share/powershell/Modules> Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false Perform operation? Performing operation 'Update PowerCLI configuration.'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayD eprecati onWarnin gs ----- ----------- ------------------- ------------------------ -------- Session UseSystemProxy Multiple Ignore True User Ignore AllUsers
■PowerCLIモジュール配置後の確認
モジュールを/usr/local/share/powershell/Modulesに配置した後、有効なモジュールを再確認してみます。
PS /usr/local/share/powershell/Modules> Get-Module -ListAvailable Directory: /usr/local/share/powershell/Modules ModuleType Version PreRelease Name PSEdition ---------- ------- ---------- ---- --------- Script 12.1.0.17 VMware.CloudServices Desk Script 7.0.0.159 VMware.DeployAutomation Desk Script 7.0.0.159 VMware.ImageBuilder Desk Script 7.0.1.169 VMware.Vim Desk Script 12.1.0.16 VMware.VimAutomation.Cis.Core Desk Script 12.0.0.15 VMware.VimAutomation.Cloud Desk Script 12.1.0.16 VMware.VimAutomation.Common Desk Script 12.1.0.16 VMware.VimAutomation.Core Desk Script 12.1.0.17 VMware.VimAutomation.Hcx Desk Script 7.13.0.16 VMware.VimAutomation.HorizonView Desk Script 12.0.0.15 VMware.VimAutomation.License Desk Script 12.0.0.15 VMware.VimAutomation.Nsxt Desk Script 12.1.0.16 VMware.VimAutomation.Sdk Desk Script 12.1.0.17 VMware.VimAutomation.Security Desk Script 12.1.0.17 VMware.VimAutomation.Srm Desk Script 12.1.0.17 VMware.VimAutomation.Storage Desk Script 1.6.0.0 VMware.VimAutomation.StorageUtility Desk Script 12.1.0.17 VMware.VimAutomation.Vds Desk Script 12.1.0.17 VMware.VimAutomation.Vmc Desk Script 12.0.0.15 VMware.VimAutomation.vROps Desk Script 12.1.0.17 VMware.VimAutomation.WorkloadManag Desk Script 12.1.0.16 VMware.VumAutomation Desk Directory: /opt/microsoft/powershell/7-lts/Modules ModuleType Version PreRelease Name PSEdition ---------- ------- ---------- ---- --------- Manifest 1.2.5 Microsoft.PowerShell.Archive Desk Manifest 7.0.0.0 Microsoft.PowerShell.Host Core Manifest 7.0.0.0 Microsoft.PowerShell.Management Core Manifest 7.0.0.0 Microsoft.PowerShell.Security Core Manifest 7.0.0.0 Microsoft.PowerShell.Utility Core Script 1.4.7 PackageManagement Desk Script 2.2.4.1 PowerShellGet Desk Script 2.0.5 PSDesiredStateConfiguration Core Script 2.0.2 PSReadLine Desk Binary 2.0.3 ThreadJob Desk
ちゃんと、PowerCLIのモジュールが認識されているようですね。
■PowerCLIコマンドレットの動作確認
私の家の環境だと、vCenterやNestedのESXiを立ち上げられるほどの余力がないため、コマンドが動くかどうか(vCenterにつながっていないというエラーが出るかどうか)を確認するまでに留めます。
試しに、Get-VMHostコマンドレットを実行してみます。
PS /root> Get-VMHost Get-VMHost: 2020/10/25 0:41:10 Get-VMHost You are not currently connected to any servers. Please connect first using a Connect cmdlet.
想定通り、vCenterとつながっていない時に出るエラーメッセージが出ました。
■おわりに
インターネットにつながっていない環境でも、Linux版PowerCLIをインストールすることができました。 会社環境でセキュリティ要件が厳しくても、このような感じでLinuxの管理サーバ等でPowerCLIを利用することはできそうです。 参考になれば幸いです。