PowerShell DSC と Linux
DSC による Linux の管理
PowerShell DSC は Linux にも対応しています。(Linux でも使えます。)正確には、Linux 向けの DSC エージェント及び DSC リソースの開発が進められており、GitHub 上でコード(及びバイナリ)が公開されています。
絶賛開発中ですので Windows と比較すると様々な制約がありますが、試しに使ってみる、といったレベルであれば十分利用できます。(バグを見つけたらフィードバックしましょう!)
2016/12/23 時点で対応しているディストリビューションは以下の通りです。(最新の対応状況は GitHub のプロジェクトページを参照。)
- CentOS 5, 6, and 7 (x86/x64)
- Debian GNU/Linux 6, 7 and 8 (x86/x64)
- Oracle Linux 5, 6 and 7 (x86/x64)
- Red Hat Enterprise Linux Server 5, 6 and 7 (x86/x64)
- SUSE Linux Enterprise Server 10, 11 and 12 (x86/x64)
- Ubuntu Server 12.04 LTS, 14.04 LTS, 16.04 LTS (x86/x64)
対応ディストリビューションについては、rpm 又は deb パッケージが公開されていますので、それをダウンロードしてインストールすれば利用できます。対応していないディストリビューションの場合は、コードを自力でコンパイルしてインストールする必要があります。
DSC for Linux の前提条件
DSC for Linux を利用するためには、いくつかのパッケージ(ソフトウェア)が必要です。こちらも GitHub 上に記載があります。
- glibc 2.4 以上
- openssl 0.9.8 又は 1.0.x
- libcurl 7.15.1 以上
- python 2.4 – 3.4
- python-ctypes (python のバージョンに対応したバージョン)
- omi 1.0.8-4
OpenSSL については、Requirements に 1.0 としか記載されていませんが、試したところ 1.0 系であれば(1.0.0 でなくとも)動作するようです。Python については新しすぎると正常に動作しない場合があります(ありました)ので、記載されているバージョンの範囲内とした方が無難です。
omi (Open Management Infrastructure)は DMTF (Distributed Management Task Force)の標準である CIM (Common Information Model)及び WBEM (Web-Based Enterprise Management)を Microsoft が Linux 向けに実装したものになります。ちなみに、CIM/WBEM の Windows 向け実装が WMI (Windows Management Instrumentation)です。
PowerShell DSC for Linux では CIM を利用しているため、omi が必要となります。
DSC for Linux のインストール
ここでは、Azure 上の Linux (CentOS 7.2)VM 上で DSC を使用して httpd を構成してみます。仮想マシンのデプロイは実施済みとします。
Linux 仮想マシンへ SSH でログインします。何はともあれ、まずはパッケージをアップデートしておきます。
[admin01@centos72 ~]$ sudo yum update -y [sudo] password for admin01: Loaded plugins: fastestmirror, langpacks base | 3.6 kB 00:00 extras | 3.4 kB 00:00 openlogic | 1.3 kB 00:00 updates | 3.4 kB 00:00 Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check (略) Installed: kernel.x86_64 0:3.10.0-514.2.2.el7 python2-pyasn1.noarch 0:0.1.9-7.el7 Dependency Installed: GeoIP.x86_64 0:1.5.0-11.el7 firewalld-filesystem.noarch 0:0.4.3.2-8.el7 ipset.x86_64 0:6.19-6.el7 ipset-libs.x86_64 0:6.19-6.el7 libstoragemgmt-python-clibs.x86_64 0:1.3.4-1.el7 python-firewall.noarch 0:0.4.3.2-8.el7 Updated: NetworkManager.x86_64 1:1.4.0-13.el7_3 NetworkManager-libnm.x86_64 1:1.4.0-13.el7_3 NetworkManager-team.x86_64 1:1.4.0-13.el7_3 NetworkManager-tui.x86_64 1:1.4.0-13.el7_3 WALinuxAgent.noarch 0:2.2.2-1.el7.centos abrt.x86_64 0:2.1.11-45.el7.centos abrt-addon-ccpp.x86_64 0:2.1.11-45.el7.centos abrt-addon-kerneloops.x86_64 0:2.1.11-45.el7.centos abrt-addon-pstoreoops.x86_64 0:2.1.11-45.el7.centos abrt-addon-python.x86_64 0:2.1.11-45.el7.centos abrt-addon-vmcore.x86_64 0:2.1.11-45.el7.centos abrt-addon-xorg.x86_64 0:2.1.11-45.el7.centos abrt-cli.x86_64 0:2.1.11-45.el7.centos abrt-console-notification.x86_64 0:2.1.11-45.el7.centos abrt-dbus.x86_64 0:2.1.11-45.el7.centos abrt-libs.x86_64 0:2.1.11-45.el7.centos abrt-python.x86_64 0:2.1.11-45.el7.centos abrt-retrace-client.x86_64 0:2.1.11-45.el7.centos abrt-tui.x86_64 0:2.1.11-45.el7.centos alsa-lib.x86_64 0:1.1.1-1.el7 alsa-tools-firmware.x86_64 0:1.1.0-1.el7 at.x86_64 0:3.1.13-22.el7 authconfig.x86_64 0:6.2.8-14.el7 avahi-autoipd.x86_64 0:0.6.31-17.el7 avahi-libs.x86_64 0:0.6.31-17.el7 bash.x86_64 0:4.2.46-21.el7_3 bind-libs.x86_64 32:9.9.4-38.el7_3 bind-libs-lite.x86_64 32:9.9.4-38.el7_3 bind-license.noarch 32:9.9.4-38.el7_3 bind-utils.x86_64 32:9.9.4-38.el7_3 binutils.x86_64 0:2.25.1-22.base.el7 biosdevname.x86_64 0:0.7.2-1.el7 blktrace.x86_64 0:1.0.5-8.el7 boost-system.x86_64 0:1.53.0-26.el7 boost-thread.x86_64 0:1.53.0-26.el7 btrfs-progs.x86_64 0:4.4.1-1.el7 ca-certificates.noarch 0:2015.2.6-73.el7 centos-release.x86_64 0:7-3.1611.el7.centos chkconfig.x86_64 0:1.7.2-1.el7 chrony.x86_64 0:2.1.1-4.el7.centos cifs-utils.x86_64 0:6.2-9.el7 coreutils.x86_64 0:8.22-18.el7 crda.x86_64 0:3.13_2016.02.08-1.el7 cryptsetup.x86_64 0:1.7.2-1.el7 cryptsetup-libs.x86_64 0:1.7.2-1.el7 cups-libs.x86_64 1:1.6.3-26.el7 curl.x86_64 0:7.29.0-35.el7.centos dbus.x86_64 1:1.6.12-17.el7 dbus-libs.x86_64 1:1.6.12-17.el7 device-mapper.x86_64 7:1.02.135-1.el7_3.1 device-mapper-event.x86_64 7:1.02.135-1.el7_3.1 device-mapper-event-libs.x86_64 7:1.02.135-1.el7_3.1 device-mapper-libs.x86_64 7:1.02.135-1.el7_3.1 device-mapper-persistent-data.x86_64 0:0.6.3-1.el7 dhclient.x86_64 12:4.2.5-47.el7.centos dhcp-common.x86_64 12:4.2.5-47.el7.centos dhcp-libs.x86_64 12:4.2.5-47.el7.centos dmidecode.x86_64 1:3.0-2.el7 dmraid.x86_64 0:1.0.0.rc16-28.el7 dmraid-events.x86_64 0:1.0.0.rc16-28.el7 dnsmasq.x86_64 0:2.66-21.el7 dracut.x86_64 0:033-463.el7 dracut-network.x86_64 0:033-463.el7 e2fsprogs.x86_64 0:1.42.9-9.el7 e2fsprogs-libs.x86_64 0:1.42.9-9.el7 ebtables.x86_64 0:2.0.10-15.el7 elfutils.x86_64 0:0.166-2.el7 elfutils-libelf.x86_64 0:0.166-2.el7 elfutils-libs.x86_64 0:0.166-2.el7 ethtool.x86_64 2:4.5-3.el7 expat.x86_64 0:2.1.0-10.el7_3 file.x86_64 0:5.11-33.el7 file-libs.x86_64 0:5.11-33.el7 filesystem.x86_64 0:3.2-21.el7 firewalld.noarch 0:0.4.3.2-8.el7 freetype.x86_64 0:2.4.11-12.el7 gdb.x86_64 0:7.6.1-94.el7 glib2.x86_64 0:2.46.2-4.el7 glibc.x86_64 0:2.17-157.el7_3.1 glibc-common.x86_64 0:2.17-157.el7_3.1 gnupg2.x86_64 0:2.0.22-4.el7 gnutls.x86_64 0:3.3.24-1.el7 grub2.x86_64 1:2.02-0.44.el7.centos grub2-tools.x86_64 1:2.02-0.44.el7.centos grubby.x86_64 0:8.28-18.el7 hunspell.x86_64 0:1.3.2-15.el7 hwdata.x86_64 0:0.252-8.4.el7 hyperv-daemons-license.noarch 0:0-0.29.20160216git.el7 hypervkvpd.x86_64 0:0-0.29.20160216git.el7 initscripts.x86_64 0:9.49.37-1.el7 iproute.x86_64 0:3.10.0-74.el7 iprutils.x86_64 0:2.4.13.1-1.el7 iptables.x86_64 0:1.4.21-17.el7 iputils.x86_64 0:20160308-8.el7 irqbalance.x86_64 3:1.0.7-6.el7 iw.x86_64 0:4.3-1.el7 iwl100-firmware.noarch 0:39.31.5.1-49.el7 iwl1000-firmware.noarch 1:39.31.5.1-49.el7 iwl105-firmware.noarch 0:18.168.6.1-49.el7 iwl135-firmware.noarch 0:18.168.6.1-49.el7 iwl2000-firmware.noarch 0:18.168.6.1-49.el7 iwl2030-firmware.noarch 0:18.168.6.1-49.el7 iwl3160-firmware.noarch 0:22.0.7.0-49.el7 iwl3945-firmware.noarch 0:15.32.2.9-49.el7 iwl4965-firmware.noarch 0:228.61.2.24-49.el7 iwl5000-firmware.noarch 0:8.83.5.1_1-49.el7 iwl5150-firmware.noarch 0:8.24.2.2-49.el7 iwl6000-firmware.noarch 0:9.221.4.1-49.el7 iwl6000g2a-firmware.noarch 0:17.168.5.3-49.el7 iwl6000g2b-firmware.noarch 0:17.168.5.2-49.el7 iwl6050-firmware.noarch 0:41.28.5.1-49.el7 iwl7260-firmware.noarch 0:22.0.7.0-49.el7 iwl7265-firmware.noarch 0:22.0.7.0-49.el7 kbd.x86_64 0:1.15.5-12.el7 kbd-legacy.noarch 0:1.15.5-12.el7 kbd-misc.noarch 0:1.15.5-12.el7 kernel-tools.x86_64 0:3.10.0-514.2.2.el7 kernel-tools-libs.x86_64 0:3.10.0-514.2.2.el7 kexec-tools.x86_64 0:2.0.7-50.el7 kmod.x86_64 0:20-9.el7 kmod-libs.x86_64 0:20-9.el7 kpartx.x86_64 0:0.4.9-99.el7 kpatch.noarch 0:0.3.2-1.el7 krb5-libs.x86_64 0:1.14.1-27.el7_3 libX11.x86_64 0:1.6.3-3.el7 libX11-common.noarch 0:1.6.3-3.el7 libblkid.x86_64 0:2.23.2-33.el7 libcom_err.x86_64 0:1.42.9-9.el7 libcurl.x86_64 0:7.29.0-35.el7.centos libdrm.x86_64 0:2.4.67-3.el7 libffi.x86_64 0:3.0.13-18.el7 libfprint.x86_64 0:0.5.0-4.el7 libgcc.x86_64 0:4.8.5-11.el7 libgcrypt.x86_64 0:1.5.3-13.el7_3.1 libgomp.x86_64 0:4.8.5-11.el7 libldb.x86_64 0:1.1.26-1.el7 libmount.x86_64 0:2.23.2-33.el7 libndp.x86_64 0:1.2-7.el7 libnl3.x86_64 0:3.2.28-2.el7 libnl3-cli.x86_64 0:3.2.28-2.el7 libproxy.x86_64 0:0.4.11-10.el7 libreport.x86_64 0:2.1.11-35.el7.centos libreport-centos.x86_64 0:2.1.11-35.el7.centos libreport-cli.x86_64 0:2.1.11-35.el7.centos libreport-filesystem.x86_64 0:2.1.11-35.el7.centos libreport-plugin-mailx.x86_64 0:2.1.11-35.el7.centos libreport-plugin-mantisbt.x86_64 0:2.1.11-35.el7.centos libreport-plugin-rhtsupport.x86_64 0:2.1.11-35.el7.centos libreport-plugin-ureport.x86_64 0:2.1.11-35.el7.centos libreport-python.x86_64 0:2.1.11-35.el7.centos libreport-web.x86_64 0:2.1.11-35.el7.centos libsoup.x86_64 0:2.48.1-6.el7 libss.x86_64 0:1.42.9-9.el7 libsss_idmap.x86_64 0:1.14.0-43.el7_3.4 libsss_nss_idmap.x86_64 0:1.14.0-43.el7_3.4 libstdc++.x86_64 0:4.8.5-11.el7 libstoragemgmt.x86_64 0:1.3.4-1.el7 libstoragemgmt-python.noarch 0:1.3.4-1.el7 libtalloc.x86_64 0:2.1.6-1.el7 libtasn1.x86_64 0:3.8-3.el7 libteam.x86_64 0:1.25-4.el7 libtevent.x86_64 0:0.9.28-1.el7 libtirpc.x86_64 0:0.2.4-0.8.el7 libusbx.x86_64 0:1.0.20-1.el7 libuuid.x86_64 0:2.23.2-33.el7 libwbclient.x86_64 0:4.4.4-9.el7 linux-firmware.noarch 0:20160830-49.git7534e19.el7 lm_sensors-libs.x86_64 0:3.4.0-4.20160601gitf9185e5.el7 logrotate.x86_64 0:3.8.6-12.el7 lsscsi.x86_64 0:0.27-4.el7 lua.x86_64 0:5.1.4-15.el7 lvm2.x86_64 7:2.02.166-1.el7_3.1 lvm2-libs.x86_64 7:2.02.166-1.el7_3.1 make.x86_64 1:3.82-23.el7 man-pages-overrides.x86_64 0:7.3.2-2.el7 mariadb-libs.x86_64 1:5.5.52-1.el7 mdadm.x86_64 0:3.4-14.el7 microcode_ctl.x86_64 2:2.1-16.el7 mlocate.x86_64 0:0.26-6.el7 mozjs17.x86_64 0:17.0.0-19.el7 nettle.x86_64 0:2.7.1-8.el7 nss.x86_64 0:3.21.3-2.el7_3 nss-softokn.x86_64 0:3.16.2.3-14.4.el7 nss-softokn-freebl.x86_64 0:3.16.2.3-14.4.el7 nss-sysinit.x86_64 0:3.21.3-2.el7_3 nss-tools.x86_64 0:3.21.3-2.el7_3 nss-util.x86_64 0:3.21.3-1.1.el7_3 ntpdate.x86_64 0:4.2.6p5-25.el7.centos ntsysv.x86_64 0:1.7.2-1.el7 openldap.x86_64 0:2.4.40-13.el7 openssh.x86_64 0:6.6.1p1-31.el7 openssh-clients.x86_64 0:6.6.1p1-31.el7 openssh-server.x86_64 0:6.6.1p1-31.el7 openssl.x86_64 1:1.0.1e-60.el7 openssl-libs.x86_64 1:1.0.1e-60.el7 os-prober.x86_64 0:1.58-9.el7 pam.x86_64 0:1.1.8-18.el7 parted.x86_64 0:3.1-28.el7 pciutils.x86_64 0:3.5.1-1.el7 pciutils-libs.x86_64 0:3.5.1-1.el7 perl.x86_64 4:5.16.3-291.el7 perl-Pod-Escapes.noarch 1:1.04-291.el7 perl-Socket.x86_64 0:2.010-4.el7 perl-libs.x86_64 4:5.16.3-291.el7 perl-macros.x86_64 4:5.16.3-291.el7 pinentry.x86_64 0:0.8.1-17.el7 plymouth.x86_64 0:0.8.9-0.26.20140113.el7.centos plymouth-core-libs.x86_64 0:0.8.9-0.26.20140113.el7.centos plymouth-scripts.x86_64 0:0.8.9-0.26.20140113.el7.centos polkit.x86_64 0:0.112-9.el7 procps-ng.x86_64 0:3.3.10-10.el7 psacct.x86_64 0:6.6.1-11.el7 pytalloc.x86_64 0:2.1.6-1.el7 python.x86_64 0:2.7.5-48.el7 python-libs.x86_64 0:2.7.5-48.el7 python-perf.x86_64 0:3.10.0-514.2.2.el7 python-pycurl.x86_64 0:7.19.0-19.el7 python-urlgrabber.noarch 0:3.10-8.el7 quota.x86_64 1:4.01-14.el7 quota-nls.noarch 1:4.01-14.el7 rdma.noarch 0:7.3_4.7_rc2-5.el7 rng-tools.x86_64 0:5-8.el7 rpcbind.x86_64 0:0.2.0-38.el7 rpm.x86_64 0:4.11.3-21.el7 rpm-build-libs.x86_64 0:4.11.3-21.el7 rpm-libs.x86_64 0:4.11.3-21.el7 rpm-python.x86_64 0:4.11.3-21.el7 rsyslog.x86_64 0:7.4.7-16.el7 samba-client-libs.x86_64 0:4.4.4-9.el7 samba-common.noarch 0:4.4.4-9.el7 samba-common-libs.x86_64 0:4.4.4-9.el7 samba-common-tools.x86_64 0:4.4.4-9.el7 samba-libs.x86_64 0:4.4.4-9.el7 satyr.x86_64 0:0.13-14.el7 setup.noarch 0:2.8.71-7.el7 sg3_utils-libs.x86_64 0:1.37-9.el7 shadow-utils.x86_64 2:4.1.5.1-24.el7 smartmontools.x86_64 1:6.2-7.el7 sos.noarch 0:3.3-5.el7.centos sssd-client.x86_64 0:1.14.0-43.el7_3.4 sudo.x86_64 0:1.8.6p7-21.el7_3 sysstat.x86_64 0:10.1.5-11.el7 systemtap-runtime.x86_64 0:3.0-7.el7 tar.x86_64 2:1.26-31.el7 tcsh.x86_64 0:6.18.01-13.el7 teamd.x86_64 0:1.25-4.el7 traceroute.x86_64 3:2.0.22-2.el7 tuned.noarch 0:2.7.1-3.el7_3.1 tzdata.noarch 0:2016j-1.el7 unzip.x86_64 0:6.0-16.el7 usb_modeswitch.x86_64 0:2.4.0-5.el7 usb_modeswitch-data.noarch 0:20160612-2.el7 util-linux.x86_64 0:2.23.2-33.el7 vim-common.x86_64 2:7.4.160-1.el7_3.1 vim-enhanced.x86_64 2:7.4.160-1.el7_3.1 vim-filesystem.x86_64 2:7.4.160-1.el7_3.1 vim-minimal.x86_64 2:7.4.160-1.el7_3.1 virt-what.x86_64 0:1.13-8.el7 wget.x86_64 0:1.14-13.el7 wpa_supplicant.x86_64 1:2.0-20.el7 xdg-utils.noarch 0:1.1.0-0.17.20120809git.el7 xfsprogs.x86_64 0:4.5.0-8.el7 xz.x86_64 0:5.2.2-1.el7 xz-libs.x86_64 0:5.2.2-1.el7 yum.noarch 0:3.4.3-150.el7.centos yum-langpacks.noarch 0:0.4.2-7.el7 yum-plugin-fastestmirror.noarch 0:1.1.31-40.el7 yum-utils.noarch 0:1.1.31-40.el7 zip.x86_64 0:3.0-11.el7 zlib.x86_64 0:1.2.7-17.el7 Replaced: python-pyasn1.noarch 0:0.1.6-2.el7 Complete! [admin01@centos72 ~]$
kernel が Update されたので、念のため再起動しておきます。
[admin01@centos72 ~]$ sudo shutdown -r now [sudo] password for admin01:
omi と dsc のパッケージを wget でダウンロードしてインストールします。CentOS 7 の場合は、以下の rpm を使用します。
- https://github.com/Microsoft/omi/releases/download/v1.1.0-0/omi-1.1.0.ssl_100.x64.rpm
- https://github.com/Microsoft/PowerShell-DSC-for-Linux/releases/download/v1.1.1-294/dsc-1.1.1-294.ssl_100.x64.rpm
[admin01@centos72 ~]$ uptime 12:01:41 up 3 min, 1 user, load average: 0.09, 0.21, 0.11 [admin01@centos72 ~]$ wget https://github.com/Microsoft/omi/releases/download/v1.1.0-0/omi-1.1.0.ssl_100.x64.rpm --2016-12-23 12:03:05-- https://github.com/Microsoft/omi/releases/download/v1.1.0-0/omi-1.1.0.ssl_100.x64.rpm Resolving github.com (github.com)... 192.30.253.112, 192.30.253.113 Connecting to github.com (github.com)|192.30.253.112|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://github-cloud.s3.amazonaws.com/releases/46681501/48043966-644a-11e6-9229-10d424e119a1.rpm?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20161223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20161223T120306Z&X-Amz-Expires=300&X-Amz-Signature=55d94084803fef29dd768ffe6582061fc480ac49f8ee741d6ade2902274bf1d7&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Domi-1.1.0.ssl_100.x64.rpm&response-content-type=application%2Foctet-stream [following] --2016-12-23 12:03:06-- https://github-cloud.s3.amazonaws.com/releases/46681501/48043966-644a-11e6-9229-10d424e119a1.rpm?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20161223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20161223T120306Z&X-Amz-Expires=300&X-Amz-Signature=55d94084803fef29dd768ffe6582061fc480ac49f8ee741d6ade2902274bf1d7&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Domi-1.1.0.ssl_100.x64.rpm&response-content-type=application%2Foctet-stream Resolving github-cloud.s3.amazonaws.com (github-cloud.s3.amazonaws.com)... 54.231.81.0 Connecting to github-cloud.s3.amazonaws.com (github-cloud.s3.amazonaws.com)|54.231.81.0|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 6180206 (5.9M) [application/octet-stream] Saving to: ‘omi-1.1.0.ssl_100.x64.rpm’ 100%[======================================>] 6,180,206 2.32MB/s in 2.5s 2016-12-23 12:03:10 (2.32 MB/s) - ‘omi-1.1.0.ssl_100.x64.rpm’ saved [6180206/6180206] [admin01@centos72 ~]$ wget https://github.com/Microsoft/PowerShell-DSC-for-Linux/releases/download/v1.1.1-294/dsc-1.1.1-294.ssl_100.x64.rpm --2016-12-23 12:03:14-- https://github.com/Microsoft/PowerShell-DSC-for-Linux/releases/download/v1.1.1-294/dsc-1.1.1-294.ssl_100.x64.rpm Resolving github.com (github.com)... 192.30.253.113, 192.30.253.112 Connecting to github.com (github.com)|192.30.253.113|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://github-cloud.s3.amazonaws.com/releases/19926695/f3091de6-6f89-11e6-8a38-199f991e92e4.rpm?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20161223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20161223T120314Z&X-Amz-Expires=300&X-Amz-Signature=e5156607f9670240562225e3e55196451ef1aa490211dd58ce0a886e5fa2db0d&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Ddsc-1.1.1-294.ssl_100.x64.rpm&response-content-type=application%2Foctet-stream [following] --2016-12-23 12:03:15-- https://github-cloud.s3.amazonaws.com/releases/19926695/f3091de6-6f89-11e6-8a38-199f991e92e4.rpm?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20161223%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20161223T120314Z&X-Amz-Expires=300&X-Amz-Signature=e5156607f9670240562225e3e55196451ef1aa490211dd58ce0a886e5fa2db0d&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Ddsc-1.1.1-294.ssl_100.x64.rpm&response-content-type=application%2Foctet-stream Resolving github-cloud.s3.amazonaws.com (github-cloud.s3.amazonaws.com)... 54.231.40.171 Connecting to github-cloud.s3.amazonaws.com (github-cloud.s3.amazonaws.com)|54.231.40.171|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 5807498 (5.5M) [application/octet-stream] Saving to: ‘dsc-1.1.1-294.ssl_100.x64.rpm’ 100%[======================================>] 5,807,498 2.31MB/s in 2.4s 2016-12-23 12:03:18 (2.31 MB/s) - ‘dsc-1.1.1-294.ssl_100.x64.rpm’ saved [5807498/5807498] [admin01@centos72 ~]$ sudo rpm -Uvh omi-1.1.0.ssl_100.x64.rpm dsc-1.1.1-294.ssl_100.x64.rpm [sudo] password for admin01: warning: omi-1.1.0.ssl_100.x64.rpm: Header V3 RSA/SHA256 Signature, key ID be1229cf: NOKEY Preparing... ################################# [100%] Unconfiguring omid (systemd) service ... Removed symlink /etc/systemd/system/multi-user.target.wants/omid.service. Updating / installing... 1:omi-1.1.0-0 ################################# [ 33%] ************************************************************ * Warning: The certificate and keyfile were not generated * * since they already exist. * ************************************************************ omi already configured Configuring OMI service ... Created symlink from /etc/systemd/system/multi-user.target.wants/omid.service to /usr/lib/systemd/system/omid.service. Checking for ctypes python module...ok! 2:dsc-1.1.1-294 ################################# [ 67%] Installing resource MSFT_nxGroupResource Installing resource MSFT_nxFileResource Installing resource MSFT_nxUserResource Installing resource MSFT_nxArchiveResource Installing resource MSFT_nxServiceResource Installing resource MSFT_nxScriptResource Installing resource MSFT_nxFileLineResource Installing resource MSFT_nxPackageResource Installing resource MSFT_nxSshAuthorizedKeysResource Installing resource MSFT_nxEnvironmentResource Cleaning up / removing... 3:omi-1.0.8-6 ################################# [100%] [admin01@centos72 ~]$
omid (OMI Server)が起動していることを確認します。
[admin01@centos72 ~]$ sudo systemctl status omid ● omid.service - OMI CIM Server Loaded: loaded (/usr/lib/systemd/system/omid.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2016-12-23 12:03:39 UTC; 1min 31s ago Process: 1774 ExecStop=/opt/omi/bin/omiserver -s (code=exited, status=0/SUCCESS) Process: 1806 ExecStart=/opt/omi/bin/omiserver -d (code=exited, status=0/SUCCESS) Process: 1776 ExecStartPre=/opt/omi/bin/support/installssllinks (code=exited, status=0/SUCCESS) Main PID: 1810 (omiserver) CGroup: /system.slice/omid.service mq1810 /opt/omi/bin/omiserver -d Dec 23 12:03:39 centos72 systemd[1]: Starting OMI CIM Server... Dec 23 12:03:39 centos72 systemd[1]: PID file /var/opt/omi/run/omiserver.pi...t. Dec 23 12:03:39 centos72 systemd[1]: Started OMI CIM Server. Hint: Some lines were ellipsized, use -l to show in full. [admin01@centos72 ~]$
また、現時点で Apache (httpd) がインストールされていないことを確認しておきます。(この後、DSC から構成するため。)
[admin01@centos72 ~]$ sudo rpm -qa | grep httpd [admin01@centos72 ~]$
最後に、root のパスワードを構成しておきます。(既に root のパスワードを付与している場合は、改めて設定する必要はありません。)今のところ、DSC for Linux では root を使用して CIM セッションを確立し構成を行います。Credential として root アカウントおよびパスワードを使用するため、root のパスワードが設定されている必要があります。
[admin01@centos72 ~]$ sudo passwd root [sudo] password for admin01: Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully. [admin01@centos72 ~]$
Linux 向け Configuration の作成
Linux 向けの構成(Configuration)も基本的な構文は同じです。利用できる DSC リソースが Windows のものとは異なりますので、Linux 用の DSC リソースを使用します。
Windows ホスト上で Linux 向けの DSC Configuration を作成する場合や、Windows ホストから Linux に向けて Configuration を PUSH する場合(Windows 上でコンパイルする場合)、Windows で PULL サーバーを実装する場合は、nx モジュール(Linux 向けの DSC コアリソースが含まれるモジュール)をインストールする必要があります。
nx リソースは PowerShell Gallery で公開されていますので、Install-Module コマンドなどを使用してインストールできます。
Windows PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS C:\Users\admin01> Find-Module nx NuGet provider is required to continue PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 'C:\Users\admin01\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Version Name Repository Description ------- ---- ---------- ----------- 1.0 nx PSGallery Module with DSC Resources for Linux PS C:\Users\admin01> Install-Module nx Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y PS C:\Users\admin01> Get-Module nx -ListAvailable Directory: C:\Program Files\WindowsPowerShell\Modules ModuleType Version Name ExportedCommands ---------- ------- ---- ---------------- Manifest 1.0 nx PS C:\Users\admin01>
初めて Find-Module / Install-Module などを使用する場合は NuGet Provider のインストールが必要になりますので、表示に従ってインストールします。
nx モジュールをインストールすると、Linux 向けの DSC リソースを利用できるようになります。Linux 向けの DSC リソースは nx から始まるリソース名となっています。(今のところ)
PS C:\Users\admin01> Get-DscResource ImplementedAs Name ModuleName Version Properties ------------- ---- ---------- ------- ---------- Binary File {DestinationPath, Attributes, Ch... Binary nxArchive {DestinationPath, SourcePath, Ch... Binary nxEnvironment {Name, DependsOn, Ensure, Path...} Binary nxFile {DestinationPath, Checksum, Cont... Binary nxFileLine {ContainsLine, FilePath, Depends... Binary nxGroup {GroupName, DependsOn, Ensure, M... Binary nxPackage {Name, Arguments, DependsOn, Ens... Binary nxScript {GetScript, SetScript, TestScrip... Binary nxService {Controller, Name, DependsOn, En... Binary nxSshAuthorizedKeys {KeyComment, DependsOn, Ensure, ... Binary nxUser {UserName, DependsOn, Descriptio... Binary SignatureValidation {SignedItemType, TrustedStorePath} PowerShell Archive PSDesiredStateConfiguration 1.1 {Destination, Path, Checksum, Cr... PowerShell Environment PSDesiredStateConfiguration 1.1 {Name, DependsOn, Ensure, Path...} PowerShell Group PSDesiredStateConfiguration 1.1 {GroupName, Credential, DependsO... Composite GroupSet PSDesiredStateConfiguration 1.1 {DependsOn, PsDscRunAsCredential... Binary Log PSDesiredStateConfiguration 1.1 {Message, DependsOn, PsDscRunAsC... PowerShell Package PSDesiredStateConfiguration 1.1 {Name, Path, ProductId, Argument... Composite ProcessSet PSDesiredStateConfiguration 1.1 {DependsOn, PsDscRunAsCredential... PowerShell Registry PSDesiredStateConfiguration 1.1 {Key, ValueName, DependsOn, Ensu... PowerShell Script PSDesiredStateConfiguration 1.1 {GetScript, SetScript, TestScrip... PowerShell Service PSDesiredStateConfiguration 1.1 {Name, BuiltInAccount, Credentia... Composite ServiceSet PSDesiredStateConfiguration 1.1 {DependsOn, PsDscRunAsCredential... PowerShell User PSDesiredStateConfiguration 1.1 {UserName, DependsOn, Descriptio... PowerShell WaitForAll PSDesiredStateConfiguration 1.1 {NodeName, ResourceName, Depends... PowerShell WaitForAny PSDesiredStateConfiguration 1.1 {NodeName, ResourceName, Depends... PowerShell WaitForSome PSDesiredStateConfiguration 1.1 {NodeCount, NodeName, ResourceNa... PowerShell WindowsFeature PSDesiredStateConfiguration 1.1 {Name, Credential, DependsOn, En... Composite WindowsFeatureSet PSDesiredStateConfiguration 1.1 {DependsOn, PsDscRunAsCredential... PowerShell WindowsOptionalFeature PSDesiredStateConfiguration 1.1 {Name, DependsOn, Ensure, LogLev... Composite WindowsOptionalFeatureSet PSDesiredStateConfiguration 1.1 {DependsOn, PsDscRunAsCredential... PowerShell WindowsPackageCab PSDesiredStateConfiguration 1.1 {Ensure, Name, SourcePath, Depen... PowerShell WindowsProcess PSDesiredStateConfiguration 1.1 {Arguments, Path, Credential, De... PS C:\Users\admin01>
この状態になれば、Windows ホスト上でも Linux 用の DSC Configuration を記述しコンパイル(MOF ファイルを生成)できるようになります。
以下のスクリプト(DSC Configuration)を記述して、ps1 ファイルとして保存します。
※パスワード及び SSH 公開鍵の値は適切なものに変更してください。
Configuration LinuxConfig { param ( [parameter(mandatory)] [string[]]$Node ) Import-DscResource -Module nx Node $Node { nxGroup TestGroup { GroupName = "testgrp" Ensure = "Present" } nxUser TestUser { UserName = "testuser" Ensure = "Present" Password = '$6$fZAne/Qc$MZejMrOxDK0ogv9SLiBP5J5qZFBvXLnDu8HY1Oy7ycX.Y3C7mGPUfeQy3A82ev3zIabhDQnj2ayeuGn02CqE/0' HomeDirectory = "/home/testuser" Description = "test user" GroupID = "testgrp" DependsOn = "[nxGroup]TestGroup" } nxSshAuthorizedKeys ScugjSSHKey { UserName = "testuser" Key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCX8+lLrYjJYYJv0XPIinEkuUpudcj2Z7TzFMxY+QEFfKXIOC8a2hOmA5kSOchYowDQjujVWOJv07cB9756ce2CJ9BGEmRKUq1ws0fUix9fTziN7n7f/I2UO6rOkUoZwcUdNVXeDdx0CR8IWxXrP1q490nLwFYfL/Tee6RVmn9DVPx6uS/ZAJkBqDcD189BpeKcps18y8tcYUaIe7ner7j30bj+6icqOgYLfHShc62L8DK6v8YDumLY76PhHGCkCZwl8SA4upuMEQJeROcOaSsIBMq4KU1Ljezgu54L4VCIyN71itw/wtIx+7gVagVjx0sGm4BxDWNoyM3ObpFaTSqx testuser@linux' Ensure = "Present" KeyComment = "SSH RSA for testuser" DependsOn = "[nxUser]TestUser" } nxPackage Apache2 { Name = "httpd" Ensure = "Present" PackageManager = "yum" } nxService Apache2Service { Name = "httpd" State = "running" Enabled = $true Controller = "systemd" DependsOn = "[nxPackage]Apache2" } nxFile TestFile { Type = "File" Ensure = "Present" DestinationPath = "/var/www/html/welcome.html" Contents = " <h1>Merry Christmas!!</h1> " DependsOn = "[nxPackage]Apache2" } } }
Configuration の PUSH による Linux の構成
Linux ターゲットに対しても Windows と同様、Pull と Push 両方の展開方法を利用できます。Pull を使用する場合は、Windows の場合と同様、Pull サーバーの場所などを LCM (ローカル構成マネージャー、Linux の場合は Linux DSC エージェント)へ設定しておく必要があります。
ここでは Windows ホストから構成を Push してみます。前述の通り、Windows ホストから Linux 向けの Configuration をコンパイルして Push する場合は、nx モジュールを事前にインストールしておく必要があります。
※Linux ホストと同じ仮想ネットワークにデプロイされている Windows ホストから Push します。異なるネットワークから構成を Push する場合は、CIM セッションを確立できるよう FW など(Azure の場合は NSG など)の構成が必要となる場合があります。
まずは、作成した Configuration を PowerShell 上でロードしておきます。その後、MOF ファイルを生成します。
PS C:\Windows\system32> $Node = "centos72" PS C:\Windows\system32> LinuxConfig -Node $Node -OutputPath $env:TEMP Directory: C:\Users\admin01\AppData\Local\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/23/2016 12:34 PM 6590 centos72.mof PS C:\Windows\system32>
ターゲットとなる Linux ホストへ接続性があることを確認しておきます。
PS C:\Windows\system32> Test-Connection $Node Source Destination IPV4Address IPV6Address Bytes Time(ms) ------ ----------- ----------- ----------- ----- -------- TESTVM01 centos72 10.0.0.5 32 3 TESTVM01 centos72 10.0.0.5 32 0 TESTVM01 centos72 10.0.0.5 32 2 TESTVM01 centos72 10.0.0.5 32 8 PS C:\Windows\system32>
接続に使用する Credential の情報を入力します。root アカウントのパスワードを入力します。また、接続は SSL により保護されますが、SSL で使用される証明書がデフォルトでは自己署名証明書となっているため、証明書のチェックなどをスキップするよう接続オプションを構成します。(本番環境では、外部又は社内の認証局から発行された証明書を使用したほうが良いでしょう。)
PS C:\Windows\system32> $cred = Get-Credential -UserName "root" -Message "Enter password." PS C:\Windows\system32> $opt = New-CimSessionOption -UseSsl:$true -SkipCACheck:$true -SkipCNCheck:$true -SkipRevocationCheck:$true PS C:\Windows\system32> $s = New-CimSession -ComputerName $Node -Credential $cred -Port:5986 -Authentication Basic -SessionOption:$opt -OperationTimeoutSec:90 PS C:\Windows\system32> Get-CimSession Id : 1 Name : CimSession1 InstanceId : e37e1c4a-1162-43b5-908f-367ffd3384d9 ComputerName : centos72 Protocol : WSMAN PS C:\Windows\system32>
CIM セッションを確立できたら、DSC Configuration を PUSH します。
PS C:\Windows\system32> Start-DscConfiguration -Path $env:TEMP -CimSession $s -Wait -Verbose -Force VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. VERBOSE: Operation 'Invoke CimMethod' complete. VERBOSE: Time taken for configuration job to complete is 15.693 seconds PS C:\Windows\system32>
Windows と異なり、Linux の場合は各リソースの構成状況が表示されません。(現時点では。)何かエラーが発生した場合は、エラーが表示されます。
構成が正常に完了した場合、httpd がインストールされ、welcome.html が配置されているはずです。
[admin01@centos72 ~]$ sudo rpm -qa | grep httpd [sudo] password for admin01: httpd-tools-2.4.6-45.el7.centos.x86_64 httpd-2.4.6-45.el7.centos.x86_64 [admin01@centos72 ~]$ sudo systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2016-12-23 12:44:00 UTC; 9min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 4589 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service tq4589 /usr/sbin/httpd -DFOREGROUND tq4590 /usr/sbin/httpd -DFOREGROUND tq4591 /usr/sbin/httpd -DFOREGROUND tq4592 /usr/sbin/httpd -DFOREGROUND tq4593 /usr/sbin/httpd -DFOREGROUND mq4594 /usr/sbin/httpd -DFOREGROUND Dec 23 12:44:00 centos72 systemd[1]: Starting The Apache HTTP Server... Dec 23 12:44:00 centos72 httpd[4589]: AH00558: httpd: Could not reliably de...ge Dec 23 12:44:00 centos72 systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full. [admin01@centos72 ~]$ ls -lha /var/www/html/welcome.html -rw-r--r--. 1 root root 26 Dec 23 12:44 /var/www/html/welcome.html [admin01@centos72 ~]$ cat /var/www/html/welcome.html <h1>Merry Christmas!!</h1> [admin01@centos72 ~]$
ブラウザでアクセスすると、配置したページを表示できます。
また、テストユーザーも生成できています。
[admin01@centos72 ~]$ id testuser uid=1001(testuser) gid=1001(testgrp) groups=1001(testgrp) [admin01@centos72 ~]$
まとめ
Linux でも DSC を用いて構成を行うことができます。まだまだ DSC リソースが充実していないため、できることが限られている印象はありますが、PowerShell for Linux の開発と併せて DSC リソースも充実していくことを期待です。
GitHub 上で開発が進められているため、フィードバックしやすい部分もありますので、バグを発見された方は是非ご報告を!
今回まとめきれなかった Azure Automation DSC で Linux をオンボードする方法は、また何れまとめたいと思います。
コメントを残す