vim のヤンクでクリップボードにコピーしたかった話、あるいは vim 8 へのアップグレード (mac)
環境
OS | vim version |
---|---|
OSX 10.11.6 | 7.3 |
目的
mac の vim でヤンクしてクリップボードにいれたかった。
記事にしようと思ったきっかけ
よくある設定を .vimrc に書いてみましたが、有効にならず。
set clipboard=unnamed,autoselect
$ vim --version | grep clipboard -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments -xterm_clipboard -xterm_save
記録しておこうと思いました。
ぐぐった
homebrew を update して、 vim をインストールしなおすのが手っ取り早いようでした。 http://djangoapplab.com/43/
homebrew の update
まず、sudo brew update してみたら怒られました。
Error: Running Homebrew as root is extremely dangerous and no longer supported. As Homebrew does not drop privileges on installation you would be giving all build scripts full access to your system.
そうなんですね。ごめんなさい。
なので一般ユーザで update してみます。
$ brew update Error: /usr/local is not writable. You should change the ownership and permissions of /usr/local back to your user account: sudo chown -R $(whoami) /usr/local
そうなんですね。
では、と chown して update すると進みはじめ、どかどか色々とインストールされていきます。
$ brew update ==> Homebrew has enabled anonymous aggregate user behaviour analytics. Read the analytics documentation (and how to opt-out) here: http://docs.brew.sh/Analytics.html Updated 3 taps (caskroom/cask, homebrew/binary, homebrew/core). ==> Cleaning up /Library/Caches/Homebrew... Removing: /Library/Caches/Homebrew/gcc-5.3.0.tar.bz2... (91M) Removing: /Library/Caches/Homebrew/gmp-6.1.0.el_capitan.bottle.tar.gz... (1M) Removing: /Library/Caches/Homebrew/isl-0.15.el_capitan.bottle.tar.gz... (1.2M) Removing: /Library/Caches/Homebrew/mpfr-3.1.3.el_capitan.bottle.tar.gz... (862.5K) Removing: /Library/Caches/Homebrew/openssl-1.0.2g.el_capitan.bottle.tar.gz... (3.6M) Removing: /Library/Caches/Homebrew/packer-0.10.0_1.el_capitan.bottle.tar.gz... (8.4M) Removing: /Library/Caches/Homebrew/pkg-config-0.29.1.el_capitan.bottle.tar.gz... (235.8K) Removing: /Library/Caches/Homebrew/ruby-build-20160330.tar.gz... (43.7K) Removing: /Library/Caches/Homebrew/sshrc-0.5.tar.gz... (3.4K) Removing: /Library/Caches/Homebrew/terraform-0.6.14.el_capitan.bottle.tar.gz.incomplete... (94.2M) Removing: /Library/Caches/Homebrew/tig-2.1.1.el_capitan.bottle.2.tar.gz... (154.4K) ==> Migrating /Library/Caches/Homebrew to /Users/rriifftt/Library/Caches/Homebrew... ==> Deleting /Library/Caches/Homebrew... 中略
/Library/
からホームディレクトリにマイグレーションしています。とても親切です。
さらに Formulae も新しくなっているようでした。
==> Migrating d-bus to dbus ==> Unlinking d-bus Moving to: /usr/local/Cellar/dbus ==> Linking dbus Error: Could not link: /usr/local/share/doc/homebrew Please delete these paths and run `brew update`. ==> Migrating HOMEBREW_REPOSITORY (please wait)... Error: Could not link: /usr/local/share/doc/homebrew Please delete these paths and run `brew update`. ==> Migrated HOMEBREW_REPOSITORY to /usr/local/Homebrew! Homebrew no longer needs to have ownership of /usr/local. If you wish you can return /usr/local to its default ownership with: sudo chown root:wheel /usr/local
最後には ↑ のログが出力されました。
ご案内の通りにします。
$ rm -rf /usr/local/share/doc/homebrew $ brew update Already up-to-date.
成功しました。
さらにご案内の通り /usr/local の権限を元に戻しておきます。
$ sudo chown root:wheel /usr/local
vim のインストール
vim は upgrade すればいいでしょと思ってやってみるとインストールされていないって言われました。
$ brew upgrade vim Error: vim not installed
clipboard が有効にならないのはこれが原因っぽいような。
ないなら install します。
$ brew install vim ==> Installing dependencies for vim: perl, readline, libyaml, openssl, ruby, pkg-config, sqlite, gdbm, python ==> Installing vim dependency: perl ==> Downloading https://homebrew.bintray.com/bottles/perl-5.24.0_1.el_capitan.bottle.1.tar.gz ######################################################################## 100.0% ==> Pouring perl-5.24.0_1.el_capitan.bottle.1.tar.gz 略 ==> Pouring vim-8.0.0329.el_capitan.bottle.tar.gz 🍺 /usr/local/Cellar/vim/8.0.0329: 1,713 files, 23.3M
vim 8 が降ってきました。
バイナリの切替
clipboard が有効になっているか確認してみると、変わっていません。
$ vim --version | grep clipboard -clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments -xterm_clipboard -xterm_save
vim インストール時のログを見ると別の場所にインストールされたようです。
こちらのバイナリで確認してみると有効になっています。
$ /usr/local/Cellar/vim/8.0.0329/bin/vim --version | grep clipboard +clipboard +job +path_extra +user_commands +eval +mouse_dec +statusline -xterm_clipboard
入れ替える必要がありそうなので入れ替えてみます。
$ mv /usr/local/bin/vim{,.bk} $ ln -s /usr/local/Cellar/vim/8.0.0329/bin/vim /usr/local/bin/vim
vim を起動する
と、エラーが出ました。
$ vim Command terminated Error detected while processing /Users/rriifftt/.vim/bundle/open-browser.vim/plugin/openbrowser.vim: line 19: E484: Can't open file /var/folders/g5/hsvhp9155l1c6sdc01rgqd4jwp37f2/T/v7qsLTu/0 Press ENTER or type command to continue
さらに iTerm で新しいタブを開くとローカルホストにログインできなくなりました。
Last login: Tue Feb 14 11:15:10 on ttys019 dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib Referenced from: /usr/local/bin/bash Reason: image not found
やさしい人に readline を切り替えるとよくなるかもしれないと教えてもらいました。
確かに brew update した時に readline が更新されています。
==> Pouring readline-7.0.1.el_capitan.bottle.tar.gz ==> Caveats This formula is keg-only, which means it was not symlinked into /usr/local. macOS provides the BSD libedit library, which shadows libreadline. In order to prevent conflicts when programs look for libreadline we are defaulting this GNU Readline installation to keg-only. For compilers to find this software you may need to set: LDFLAGS: -L/usr/local/opt/readline/lib CPPFLAGS: -I/usr/local/opt/readline/include ==> Summary 🍺 /usr/local/Cellar/readline/7.0.1: 46 files, 2M ==> Installing vim dependency: libyaml ==> Downloading https://homebrew.bintray.com/bottles/libyaml-0.1.7.el_capitan.bottle.tar.gz
readline の切替
readline を切り替えてみます。
$ brew switch readline 7.0 Error: readline does not have a version "7.0" in the Cellar. Versions available: 6.3.6, 6.3.8, 7.0.1
コマンドエラーになってしまいましたが、3 つのバージョンがあることがわかりました。
そして現在のバージョンは以下です。
$ brew list readline /usr/local/Cellar/readline/7.0.1/include/readline/ (8 files) /usr/local/Cellar/readline/7.0.1/lib/libhistory.7.0.dylib /usr/local/Cellar/readline/7.0.1/lib/libreadline.7.0.dylib /usr/local/Cellar/readline/7.0.1/lib/ (6 other files) /usr/local/Cellar/readline/7.0.1/share/doc/ (3 files) /usr/local/Cellar/readline/7.0.1/share/info/ (3 files) /usr/local/Cellar/readline/7.0.1/share/man/ (2 files) /usr/local/Cellar/readline/7.0.1/share/readline/ (15 files)
最新版は色々とアレなんでしょうか。
6.3.8 に切り替えてみます。
$ brew switch readline 6.3.8 Cleaning /usr/local/Cellar/readline/6.3.6 Cleaning /usr/local/Cellar/readline/6.3.8 Cleaning /usr/local/Cellar/readline/7.0.1 Opt link created for /usr/local/Cellar/readline/6.3.8
再度 vim を起動する
と、エラーなく起動できました。
iTerm の新規タブも問題なく開くことができています。
いまのところはこれで問題なさそうです。
boto3 で指定された日付以前の snapshot を削除する
という python script を晒してみます。
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 指定された日付以前の snapshot を削除します ただし ami に紐付いている snapshot は削除しません example: $ python delete_expired_snapshots.py -p profile_name -o owner_id -e expire_date (--dry-run True|False) """ import boto3 import pytz from argparse import ArgumentParser from datetime import datetime, timedelta def delete_expired_snapshots(profile, owner_id, expire_date, dry_run=False,): session = boto3.Session(profile_name=profile) client = session.client("ec2") snapshots = client.describe_snapshots(OwnerIds=[owner_id]) """ response example: "Snapshots": { u'Description': '***********', u'Encrypted': True, u'VolumeId': 'vol-*****', u'KmsKeyId': 'arn:aws:kms:region:*******:key/***********', u'State': 'completed', u'VolumeSize': **, u'Progress': '100%', u'StartTime': datetime.datetime(yyyy, mm, dd, hh, MM, SS, tzinfo=tzutc()), u'SnapshotId': 'snap-************', u'OwnerId': '*******' },... """ expired_snapshot_ids = [ s["SnapshotId"] for s in snapshots["Snapshots"] if s["StartTime"] < expire_date ] for expired_snapshot_id in expired_snapshot_ids: try: res = client.delete_snapshot(SnapshotId=expired_snapshot_id, DryRun=dry_run) if res["ResponseMetadata"]["HTTPStatusCode"] == 200: print("INFO. delete Succeed id:{0}".format(expired_snapshot_id)) else: print("ERROR. delete Failed id:{0} status_code:{1}".format( expired_snapshot_id, res)) except Exception as e: print("ERROR. exception occurd id:{0}".format(expired_snapshot_id)) print("Exception. {0}".format(e)) def arg_parse_for_delete_expired_snapshots(): parser = ArgumentParser() parser.add_argument( "-p", "--profile", dest="profile", type=str, required=True, help="specify snapshots aws profile" ) parser.add_argument( "-o", "--owner-id", dest="owner_id", type=str, required=True, help="specify snapshots owner_id" ) parser.add_argument( "-e", "--expire-date", dest="expire_date", type=int, required=True, help="specify expire date" ) parser.add_argument( "--dry-run", dest="dry_run", type=bool, default=False, help="dry run switch" ) return parser.parse_args() if __name__ == "__main__": p = arg_parse_for_delete_expired_snapshots() expire_date = datetime.now(pytz.utc) - timedelta(p.expire_date) delete_expired_snapshots(p.profile, p.owner_id, expire_date, p.dry_run)
argparse をつかってコマンドライン引数をよしなにする
よくつかうのでメモとして残してみます。
argparse とは
python の組み込みライブラリで、引数をよしなにしてくれるいい人です。
python 2.7 から追加されました。
15.4. argparse — コマンドラインオプション、引数、サブコマンドのパーサー — Python 2.7.x ドキュメント
よくやること
コマンドラインで実行する系のスクリプトでオプションを指定するときなどに便利なので、そのように使うことが多いです。
ロングオプションを指定したり、変数に自動で格納してくれたり、位置をきにしなくて良かったり、 --help で Usage を自動で生成したりしてくれます。
例えば以下のようなコードを動かしてみます。
#!/usr/bin/env python # -*- coding: utf-8 -*- from argparse import ArgumentParser def argument_parser(): parser = ArgumentParser(description="this is description") parser.add_argument( "-n", "--neko", dest="neko", type=str, help="specified neko") return parser.parse_args() if __name__ == '__main__': p = argument_parser() print(p.neko)
help を表示してみます。
$ python test.py --help usage: test.py [-h] -n NEKO this is description optional arguments: -h, --help show this help message and exit -n NEKO, --neko NEKO specified neko
オプションを正しく指定すると以下の様に普通に print() されます。
$ python test.py -n saba saba $ python test.py --neko mike mike
必須オプションをつくる
require=True
を指定すると必須オプションをつくれます。
"-n", "--neko", dest="neko",
type=str,
+ required=True,
help="specified neko")
引数を与えずに実行すると、エラーになります。
$ python test.py usage: test.py [-h] -n NEKO test.py: error: argument -n/--neko is required
オプションの選択肢を固定する
choices=[]
を使うと選択肢を固定できます。
"-n", "--neko", dest="neko",
type=str,
required=True,
+ choices=["saba", "mike"],
help="specified neko")
正しく実行すると、普通です。
$ python test.py --neko saba saba 01:50:41 ~ $ python test.py --neko mike mike
choices にないオプションを与えるとエラーになります。
$ python test.py --neko kuroneko usage: test.py [-h] -n {saba,mike} test.py: error: argument -n/--neko: invalid choice: 'kuroneko' (choose from 'saba', 'mike')
順番をきにしなくてよい
2 つのオプションを定義してみます。
#!/usr/bin/env python # -*- coding: utf-8 -*- from argparse import ArgumentParser def argument_parser(): parser = ArgumentParser(description="this is description") parser.add_argument( "-n", "--neko", dest="neko", type=str, required=True, choices=["saba", "mike"], help="specified neko") parser.add_argument( "-i", "--inu", dest="inu", type=str, help="specified inu") return parser.parse_args() if __name__ == '__main__': p = argument_parser() print(p.neko) print(p.inu)
help を見てみると、オプションが自動で追加されています。
$ python test.py --help usage: test.py [-h] -n {saba,mike} [-i INU] this is description optional arguments: -h, --help show this help message and exit -n {saba,mike}, --neko {saba,mike} specified neko -i INU, --inu INU specified inu
引数の位置を変えて実行しても結果は同じになります。らくちん。
$ python test.py -n mike --inu shiba mike shiba $ python test.py -i shiba --neko saba saba shiba
おわり。
次は流行りの click を触ってみます。
CentOS7 で再起動後に vm.swappiness の設定が元に戻ってしまう
環境
CentOS 7 (x86_64) - with Updates HVM on AWS Marketplace
事象
- デフォルトは
vm.swappiness = 30
sysctl -w vm.swappiness=任意の値
すると任意の値に変更可能sysctl -p
するも reboot 後に元に戻ってしまう
原因
こちらで言及されていました。
CentOs7 vm.swappiness cannot be set on boot - CentOS
tuned によって上書きされるようです。
対応
tuned の設定ファイルは /usr/lib/tuned 配下にあるそうですので grep してみます。
# find /usr/lib/tuned -name '*.conf' -type f -exec grep "vm.swappiness" {} \+ /usr/lib/tuned/latency-performance/tuned.conf:vm.swappiness=10 /usr/lib/tuned/throughput-performance/tuned.conf:vm.swappiness=10 /usr/lib/tuned/virtual-guest/tuned.conf:vm.swappiness = 30
デフォルトでは 30 に設定されていましたので、 /usr/lib/tuned/virtual-guest/tuned.conf
の値を変更したところ、意図した通りに設定されました。
一応、編集したファイルを下記に記載します。
# # tuned configuration # [main] include=throughput-performance [sysctl] # If a workload mostly uses anonymous memory and it hits this limit, the entire # working set is buffered for I/O, and any more write buffering would require # swapping, so it's time to throttle writes until I/O can catch up. Workloads # that mostly use file mappings may be able to use even higher values. # # The generator of dirty data starts writeback at this percentage (system default # is 20%) vm.dirty_ratio = 30 # Filesystem I/O is usually much more efficient than swapping, so try to keep # swapping low. It's usually safe to go even lower than this on systems with # server-grade storage. - vm.swappiness = 30 + vm.swappiness = 5
python でディレクトリ配下の最新のファイル名(フルパス)を取得する
前提
最新かどうかはファイルの最終変更日時 = mtime で判定します。
準備
こんな感じでファイルを作成します
$ for ((i=0;i>10;i++)); do touch $i.txt; sleep 5; done
最終変更日は以下の様になりました。
9.txt の最終変更日時が最も新しいものになっています。
$ stat -f "%N %m" *.txt 0.txt 1465450197 1.txt 1465450202 2.txt 1465450207 3.txt 1465450212 4.txt 1465450217 5.txt 1465450222 6.txt 1465450227 7.txt 1465450232 8.txt 1465450237 9.txt 1465450242
表題のことをする
import os from glob import glob def get_latest_modified_file_path(dirname): target = os.path.join(dirname, '*') files = [(f, os.path.getmtime(f)) for f in glob(target)] latest_modified_file_path = sorted(files, key=lambda files: files[1])[-1] return latest_modified_file_path[0] if __name__ == '__main__': dirname = "/hoge" print(get_latest_modified_file_path(dirname))
実行するとフルパスが取得できます。
$ python get_latest_modified_file_path.py /hoge/9.txt
vagrant で windows server 2012R2 を動かす
- vagrant-winrm プラグインのインストール
- windows server の vagrant box を make する
- packer のダウンロード
- vagrant box add
- Vagrantfile
test-kitchen の中の人が手順を公開しています。
基本的に手順の内容に沿えばいいのですが感動したので備忘として。
なお、環境は ubuntu-mate 16.04 で、 ruby 2.3.0p0 です。
vagrant-winrm プラグインのインストール
$ vagrant plugin install vagrant-winrm
windows server の vagrant box を make する
~/vagrant
配下で作業します。
$ cd ~/vagrant $ git clone https://github.com/boxcutter/windows.git $ cd windows $ make virtualbox/eval-win2012r2-standard rm -rf output-virtualbox-iso mkdir -p box/virtualbox packer build -only=virtualbox-iso -var 'cm=nocm' -var 'version=1.0.4' -var 'update=false' -var 'headless=false' -var "shutdown_command=shutdown /s /t 10 /f /d p:4:1 /c Packer_Shutdown" -var "iso_url=http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO" -var "iso_checksum=7e3f89dbff163e259ca9b0d1f078daafd2fed513" eval-win2012r2-standard.json /bin/sh: 1: packer: not found Makefile:428: ターゲット 'box/virtualbox/eval-win2012r2-standard-nocm-1.0.4.box' のレシピで失敗しました make: *** [box/virtualbox/eval-win2012r2-standard-nocm-1.0.4.box] エラー 127
と、 packer がないと怒られました。
packer は hashicorp 社が提供するオープンソースのツールで、
ゴールデンイメージを作ったり vagrant box を作成したりするものです。
使ってみたいと思っていたのでタイムリー^^
というわけで packer をインストールします。
packer のダウンロード
公式からダウンロードして解凍し、パスの通ったところにバイナリを移動します。
/usr/local/src$ sudo wget https://releases.hashicorp.com/packer/0.10.1/packer_0.10.1_linux_amd64.zip /usr/local/src$ unzip packer_0.10.1_linux_amd64.zip packer packer_0.10.1_linux_amd64.zip /usr/local/src$ sudo cp packer /usr/local/sbin /usr/local/src$ packer --version 0.10.1
もう一回 make
ここからの vmware 関連のパッケージをごにょごにょしていますが、たぶん不要です
私の無駄っぽい苦労ログに興味のある方以外は ### 再再再再再 make まで飛ばしてください
$ make rm -rf output-vmware-iso mkdir -p box/vmware packer build -only=vmware-iso -var 'cm=nocm' -var 'version=1.0.4' -var 'update=false' -var 'headless=false' -var "shutdown_command=shutdown /s /t 10 /f /d p:4:1 /c Packer_Shutdown" -var "iso_url=iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso" -var "iso_checksum=7e7e9425041b3328ccf723a0855c2bc4f462ec57" win2008r2-datacenter-cygwin.json vmware-iso output will be in this color. Build 'vmware-iso' errored: Failed creating VMware driver: Unable to initialize any driver for this platform. The errors from each driver are shown below. Please fix at least one driver to continue: * exec: "vmware": executable file not found in $PATH * exec: "vmware": executable file not found in $PATH * exec: "vmplayer": executable file not found in $PATH * exec: "vmplayer": executable file not found in $PATH ==> Some builds didn't complete successfully and had errors: --> vmware-iso: Failed creating VMware driver: Unable to initialize any driver for this platform. The errors from each driver are shown below. Please fix at least one driver to continue: * exec: "vmware": executable file not found in $PATH * exec: "vmware": executable file not found in $PATH * exec: "vmplayer": executable file not found in $PATH * exec: "vmplayer": executable file not found in $PATH ==> Builds finished but no artifacts were created. Makefile:406: ターゲット 'box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box' のレシピで失敗しました make: *** [box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box] エラー 1 rriifftt@X1:~/vagrant/windows$ sudo apt install vmrun パッケージリストを読み込んでいます... 完了 依存関係ツリーを作成しています 状態情報を読み取っています... 完了 E: パッケージ vmrun が見つかりません
今度は vmrun がないと怒られます。。
http://askubuntu.com/questions/458198/xubuntu-vmware-player-missing-vmrun-utility によると、VIX SDK をインストールする必要がありそうです。
VIX SDK のインストール
公式から普通にダウンロードしてみます。
.bundle
ファイルってなんだ。。。
VMware を Ubuntu にインストールする - わかったつもりになるページ によると普通に実行すればよさそうです。
一旦実行してみます。
~/Downloads$ ls VMware-VIX-1.13.2-1744117.x86_64.bundle VMware-VIX-1.13.2-1744117.x86_64.bundle ~/Downloads$ chmod +x VMware-VIX-1.13.2-1744117.x86_64.bundle ~/Downloads$ sudo sh VMware-VIX-1.13.2-1744117.x86_64.bundle Extracting VMware Installer...done.
するとウィザードが開きます。
accept して next
インストール完了です。
再々 make
するも同じエラーで進まず。。。
vmware workstation player のインストール
次は無償で利用できる vmware workstation player をインストールを試してみます。
こちらも .bundle
なので、同様に sh から実行してみます。
ウィザードでいろいろ聞かれますが、Lisence Key は空欄にして普通にインストールします。
再再再 make
ちょっとエラーが変わった。
$ make rm -rf output-vmware-iso mkdir -p box/vmware packer build -only=vmware-iso -var 'cm=nocm' -var 'version=1.0.4' -var 'update=false' -var 'headless=false' -var "shutdown_command=shutdown /s /t 10 /f /d p:4:1 /c Packer_Shutdown" -var "iso_url=iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso" -var "iso_checksum=7e7e9425041b3328ccf723a0855c2bc4f462ec57" win2008r2-datacenter-cygwin.json vmware-iso output will be in this color. Build 'vmware-iso' errored: Failed creating VMware driver: Unable to initialize any driver for this platform. The errors from each driver are shown below. Please fix at least one driver to continue: * exec: "vmware": executable file not found in $PATH * exec: "vmware": executable file not found in $PATH * Neither 'vmware-vdiskmanager', nor 'qemu-img' found in path. One of these is required to configure disks for VMware Player. * Neither 'vmware-vdiskmanager', nor 'qemu-img' found in path. One of these is required to configure disks for VMware Player. ==> Some builds didn't complete successfully and had errors: --> vmware-iso: Failed creating VMware driver: Unable to initialize any driver for this platform. The errors from each driver are shown below. Please fix at least one driver to continue: * exec: "vmware": executable file not found in $PATH * exec: "vmware": executable file not found in $PATH * Neither 'vmware-vdiskmanager', nor 'qemu-img' found in path. One of these is required to configure disks for VMware Player. * Neither 'vmware-vdiskmanager', nor 'qemu-img' found in path. One of these is required to configure disks for VMware Player. ==> Builds finished but no artifacts were created. Makefile:406: ターゲット 'box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box' のレシピで失敗しました make: *** [box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box] エラー 1
qemu が足りないっぽい。
$ sudo apt install qemu $ make rm -rf output-vmware-iso mkdir -p box/vmware packer build -only=vmware-iso -var 'cm=nocm' -var 'version=1.0.4' -var 'update=false' -var 'headless=false' -var "shutdown_command=shutdown /s /t 10 /f /d p:4:1 /c Packer_Shutdown" -var "iso_url=iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso" -var "iso_checksum=7e7e9425041b3328ccf723a0855c2bc4f462ec57" win2008r2-datacenter-cygwin.json vmware-iso output will be in this color. Build 'vmware-iso' errored: Couldn't find VMware tools for 'windows'! VMware often downloads these tools on-demand. However, to do this, you need to create a fake VM of the proper type then click the 'install tools' option in the VMware GUI. ==> Some builds didn't complete successfully and had errors: --> vmware-iso: Couldn't find VMware tools for 'windows'! VMware often downloads these tools on-demand. However, to do this, you need to create a fake VM of the proper type then click the 'install tools' option in the VMware GUI. ==> Builds finished but no artifacts were created. Makefile:406: ターゲット 'box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box' のレシピで失敗しました make: *** [box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box] エラー 1
今度は VMware tools for windows か。。
VMware tools for windows
vmware workstation player の player preference からインストールできそうです。
いろいろとインストールされました。
再再再再 make
またエラーが変わりました。
$ make rm -rf output-vmware-iso mkdir -p box/vmware packer build -only=vmware-iso -var 'cm=nocm' -var 'version=1.0.4' -var 'update=false' -var 'headless=false' -var "shutdown_command=shutdown /s /t 10 /f /d p:4:1 /c Packer_Shutdown" -var "iso_url=iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso" -var "iso_checksum=7e7e9425041b3328ccf723a0855c2bc4f462ec57" win2008r2-datacenter-cygwin.json vmware-iso output will be in this color. ==> vmware-iso: Downloading or copying ISO vmware-iso: Downloading or copying: file:///iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso vmware-iso: Error downloading: open /iso/en_windows_server_2008_r2_with_sp1_vl_build_x64_dvd_617403.iso: no such file or directory ==> vmware-iso: ISO download failed. Build 'vmware-iso' errored: ISO download failed. ==> Some builds didn't complete successfully and had errors: --> vmware-iso: ISO download failed. ==> Builds finished but no artifacts were created. Makefile:406: ターゲット 'box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box' のレシピで失敗しました make: *** [box/vmware/win2008r2-datacenter-cygwin-nocm-1.0.4.box] エラー 1
あかん。挫けそう。
と、思ったら make 対象を指定していないことに気づきました。
もしかして vmware とか不要だった・・・?
再再再再再 make
$ make virtualbox/eval-win2012r2-standard rm -rf output-virtualbox-iso mkdir -p box/virtualbox packer build -only=virtualbox-iso -var 'cm=nocm' -var 'version=1.0.4' -var 'update=false' -var 'headless=false' -var "shutdown_command=shutdown /s /t 10 /f /d p:4:1 /c Packer_Shutdown" -var "iso_url=http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO" -var "iso_checksum=7e3f89dbff163e259ca9b0d1f078daafd2fed513" eval-win2012r2-standard.json virtualbox-iso output will be in this color. ==> virtualbox-iso: Cannot find "Default Guest Additions ISO" in vboxmanage output (or it is empty) ==> virtualbox-iso: Downloading or copying Guest additions checksums virtualbox-iso: Downloading or copying: http://download.virtualbox.org/virtualbox/5.0.18/SHA256SUMS ==> virtualbox-iso: Downloading or copying Guest additions virtualbox-iso: Downloading or copying: http://download.virtualbox.org/virtualbox/5.0.18/VBoxGuestAdditions_5.0.18.iso virtualbox-iso: Download progress: 62% virtualbox-iso: Download progress: 94% ==> virtualbox-iso: Downloading or copying ISO virtualbox-iso: Downloading or copying: http://download.microsoft.com/download/6/2/A/62A76ABB-9990-4EFC-A4FE-C7D698DAEB96/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO virtualbox-iso: Download progress: 0% virtualbox-iso: Download progress: 1% virtualbox-iso: Download progress: 2% virtualbox-iso: Download progress: 3%
進み始めました。 44min ほどかかるそうなのでしばし芋焼酎など飲みながら待ちます。
こいつ。。動くぞ。。。
終わった模様です。
==> virtualbox-iso: Gracefully halting virtual machine... virtualbox-iso: Removing floppy drive... ==> virtualbox-iso: Preparing to export machine... virtualbox-iso: Deleting forwarded port mapping for the communicator (SSH, WinRM, etc) (host port 3171) ==> virtualbox-iso: Exporting virtual machine... virtualbox-iso: Executing: export eval-win2012r2-standard --output output-virtualbox-iso/eval-win2012r2-standard.ovf ==> virtualbox-iso: Unregistering and deleting virtual machine... ==> virtualbox-iso: Running post-processor: vagrant ==> virtualbox-iso (vagrant): Creating Vagrant box for 'virtualbox' provider virtualbox-iso (vagrant): Copying from artifact: output-virtualbox-iso/eval-win2012r2-standard-disk1.vmdk virtualbox-iso (vagrant): Copying from artifact: output-virtualbox-iso/eval-win2012r2-standard.ovf virtualbox-iso (vagrant): Renaming the OVF to box.ovf... virtualbox-iso (vagrant): Using custom Vagrantfile: tpl/vagrantfile-eval-win2012r2-standard.tpl virtualbox-iso (vagrant): Compressing: Vagrantfile virtualbox-iso (vagrant): Compressing: box.ovf virtualbox-iso (vagrant): Compressing: eval-win2012r2-standard-disk1.vmdk virtualbox-iso (vagrant): Compressing: metadata.json Build 'virtualbox-iso' finished. ==> Builds finished. The artifacts of successful builds are: --> virtualbox-iso: 'virtualbox' provider box: box/virtualbox/eval-win2012r2-standard-nocm-1.0.4.
vagrant box add
手順に従って box add します。
$ vagrant box add windows-2012r2 ./box/virtualbox/eval-win2012r2-standard-nocm-1.0.4.box $ vagrant box list windows-2012r2 (virtualbox, 0)
Vagrantfile
用意されている template を利用するとよさそうです。
$ mkdir ~/vagrant/windows-2012r2 $ cp ~/vagrant/windows/tpl/vagrantfile-eval-win2012r2-standard.tpl ~/vagrant/windows-2012r2/Vagrantfile
Vagrantfile の config.vm.box を編集します。
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.define "vagrant-eval-win2012r2-standard" #config.vm.box = "eval-win2012r2-standard" config.vm.box = "windows-2012r2" # Port forward WinRM and RDP config.vm.network :forwarded_port, guest: 3389, host: 3389, id: "rdp", auto_correct:true config.vm.communicator = "winrm" config.vm.guest = :windows config.vm.network :forwarded_port, guest: 5985, host: 5985, id: "winrm", auto_correct:true # Port forward SSH #config.vm.network :forwarded_port, guest: 22, host: 2222, id: "ssh", auto_correct:true config.vm.provider :virtualbox do |v, override| v.gui = true v.customize ["modifyvm", :id, "--memory", 1536] v.customize ["modifyvm", :id, "--cpus", 1] v.customize ["modifyvm", :id, "--vram", "256"] v.customize ["setextradata", "global", "GUI/MaxGuestResolution", "any"] v.customize ["setextradata", :id, "CustomVideoMode1", "1024x768x32"] end ["vmware_fusion", "vmware_workstation"].each do |provider| config.vm.provider provider do |v, override| v.gui = true v.vmx["memsize"] = "1536" v.vmx["numvcpus"] = "1" v.vmx["cpuid.coresPerSocket"] = "1" v.vmx["ethernet0.virtualDev"] = "vmxnet3" v.vmx["RemoteDisplay.vnc.enabled"] = "false" v.vmx["RemoteDisplay.vnc.port"] = "5900" v.vmx["scsi0.virtualDev"] = "lsisas1068" end end config.vm.provider :parallels do |v, override| v.customize ["set", :id, "--cpus", 1] v.customize ["set", :id, "--memsize", 1536] v.customize ["set", :id, "--videosize", "256"] end end
起動してみます!
$ cd ~/vagrant/windows-2012r2 $ vagrant up Bringing machine 'vagrant-eval-win2012r2-standard' up with 'virtualbox' provider... ==> vagrant-eval-win2012r2-standard: Importing base box 'windows-2012r2'... ==> vagrant-eval-win2012r2-standard: Matching MAC address for NAT networking... ==> vagrant-eval-win2012r2-standard: Setting the name of the VM: windows-2012r2_vagrant-eval-win2012r2-standard_1465130882039_49088 ==> vagrant-eval-win2012r2-standard: Clearing any previously set network interfaces... ==> vagrant-eval-win2012r2-standard: Preparing network interfaces based on configuration... vagrant-eval-win2012r2-standard: Adapter 1: nat ==> vagrant-eval-win2012r2-standard: Forwarding ports... vagrant-eval-win2012r2-standard: 3389 => 3389 (adapter 1) vagrant-eval-win2012r2-standard: 5985 => 5985 (adapter 1) ==> vagrant-eval-win2012r2-standard: Running 'pre-boot' VM customizations... ==> vagrant-eval-win2012r2-standard: Booting VM... ==> vagrant-eval-win2012r2-standard: Waiting for machine to boot. This may take a few minutes... vagrant-eval-win2012r2-standard: WinRM address: 127.0.0.1:5985 vagrant-eval-win2012r2-standard: WinRM username: vagrant vagrant-eval-win2012r2-standard: WinRM transport: plaintext ==> vagrant-eval-win2012r2-standard: Machine booted and ready! ==> vagrant-eval-win2012r2-standard: Checking for guest additions in VM... ==> vagrant-eval-win2012r2-standard: Mounting shared folders... vagrant-eval-win2012r2-standard: /vagrant => /home/rriifftt/vagrant/windows-2012r2
180 日間の無償評価版が起動しました!!!
ライセンス問題もセーフっぽいですね。
これでローカルでの test-kitchen が捗りそう。。。
その辺はまた後日。。。
de:code 2016 5/25 メモ
de:code 2016 5/24 メモ - set setting reset の続きです。
powershell
DSC
- コード書く
- mof ファイルができる
- これを送って実行させる
- start-dscconfiguration
- LCM
- local configuration manager
- push は windows から実行
- pull server
- http だけでなく smb でも ok
- 各ノードが server にポーリングする
- CA を使って https 通信可能
- 運用を dsc に寄せることもできる
- Azure Automation
Docker と containter service
- windows container の話ナシ
- mesos + swarm
- microservice architecture
- 開発、移動、実行するプラットフォーム
- linux kernel
- namespace
- リソースの分断
- cgorup
- リソース管理 *コンテナ技術の標準化団体がある
- namespace
- docker が実現したこと
- software が必要な全てをファイルシステムに包む
- どのような環境でも実行を保証
- 軽量。オープン、安全
ランチ devops
best way
- 組織の文化にする
boss に聞く
- 成功するためにどうすればいいと思う?
レガシーなアプリと新しいアプリでは devops のありようが異なる
- 共通で利用できるツールを探すのがよいだろう
hashicorp
vault 推し
- セキュリティのツール
hachicorp はなぜツールを作るのか
- デプロイにまつわるサイクルを短くしたい
- 特定の課題を解決するためのツールを作成している
vagrant が一番 star されてる
- 10000 star
ms support
- 全てのプロダクトで ms をサポートしている
enterprise version がある
terraform
terraform enterprise
- チームで使うための terraform
- github や atlas をトリガーとして、terraform enterprise 上の UI から apply できる
- resource dependency graph
- modules
- collaboration
- ゴール
- インフラを進化するアプリケーションとして扱いたい
- propose
- validate in plan
- approve
- audit
- rollback
- すげぇ
- terraform enterprise 上の revert できる
- あとから問題箇所を精査してプルリクすればいいじゃん
- まるで github のような
- github integration
- notification
- remote state storage
- remote plan + applies + and locks
mesosphere
- container の大規模管理
- SAP の中の人
- chef の中の人
コンテナで複雑化した
DC/OS
- data center を一つのアプリケーションとして考える
- resource pool
- CPU
- NW
- strage...
- resource pool
- microservice(in container) = function
- 全てのバックエンドプラットフォームで対応可能
- azure container service でも OK
- ECS でも OK っぽい
- DC/OS の layer
- container orchestration
- job scheduling
- scale
- Auto Desk 社の事例
- dcos cli
- dcos dashboard
- 稼働中のアプリケーションの状況を監視できる
- application の scale の数を簡単に変更できる
- おまえら DC/OS のブログ書けよw
- data center を一つのアプリケーションとして考える
chef
- devops へのアプローチ
- infrastructure as code はなぜ必要か
- エンジニアの 7割は remote
- 会社は色々とあるが、共通でやりたいことがあるはずだ
- インフラとアプリケーションを同じように扱うべきだ
- 速いのはいいこと、ただしうまくいかなければ意味がない
- ダイナミックなインフラがなければスピーディーなビジネスはない
- 継続的に安全に実験する
- クラウドによって自動化が可能となり、自動化は反復をもたらす
- CI CD TEST なんでもやろう
- ミスの責任が単一にあるとミスを起こさないようにするために遅くなる
- 早く破綻させて破壊しろ
- みんなで解決してみんなで理解できる
- なにが間違っていたかを考える
楽しい仕事には人がやってくる
devops の分析
- 利益、生産性、デプロイ回数の向上
chef だけでなく、ワークフローが必要
- chef delivery というのがあるらしい
devops も問題点
- 監査が大変
- 監査も devops に巻き込む
- コンプライアンスはテストできる = 統制
- chef compliance
- 監査が大変
azure native な chef-client がある
どっちかというと windows のロードマップに追従している
- かなり重視しているとのこと
inspect
事例
- デプロイのコスト削減
- ビルド時間の削減
- セキュリティを先に、その次に devops というケース
chef component
- opensource と課金コンテンツあり
chef server のはなし
- recipe は step のシーケンス
- recipe に書き方
chef の TDD = TDI
dsc_script リソース
- powershell dsc をそのまま書ける
- powershell 5 から