アダルトVRエキスポ2016 レポート
2016/08/27(土)にアダルトVRエキスポ2016に行ってきました。
adult-vr.jp
秘密情報ファイルをansibleでデプロイするためにVaultを使う
先日AnsibleでMacBook Airをセットアップしたが、
秘密情報が描かれたファイルの扱いに迷ったので、調べてみた。
秘密情報が書かれたファイルについて
私の環境では色々と見られたくないもの(ちょっとしたパスワードなど)をガンガン.bashrcに書いているので、
ansibleでデプロイする際にどうすればいいのか少し迷った。
Ansibleに関するファイルは全てgithubにあげているから、
そのままアップロードするのはちょっとまずそう。
ということで、色々と調べていたらAnsibleの便利機能 "Vault" を見つけたので、試しに使ってみた。
Vaultとは?
パスワードや鍵などの秘密情報が書かれたファイルを暗号化、復号化できる機能。
これによってバージョン管理システムに安心してこれらのファイルをアップロードできる。
Ansible1.5から使えるようになった。
Ref. Vault — Ansible Documentation
とりあえずHelpを見てみる。
$ ansible-vault -h Usage: ansible-vault [create|decrypt|edit|encrypt|rekey|view] [--help] [options] vaultfile.yml Options: --ask-vault-pass ask for vault password -h, --help show this help message and exit --new-vault-password-file=NEW_VAULT_PASSWORD_FILE new vault password file for rekey --output=OUTPUT_FILE output file name for encrypt or decrypt; use - for stdout --vault-password-file=VAULT_PASSWORD_FILE vault password file -v, --verbose verbose mode (-vvv for more, -vvvv to enable connection debugging) --version show program's version number and exit
シンプルで使いやすそう。
実際に使ってみる
ここからは、実際にbashrcを暗号化してデプロイしてみる。
暗号化するファイル形式はymlである必要があるらしい。
(試しにyml以外のファイルを暗号化してみたが、デプロイ時にうまく復号化できなかった。)
ということで、秘密にしたいファイルの内容を書き出す。
復号暗号化に使うパスワードも合わせて入力。
$ ansible-vault create secret.yml Vault password:
暗号化前のファイルの中身はこんな感じ。
yml形式で書き出してある。
bashrc: | export PS1="\d \t \w$ " export LANG=en_US.UTF-8 ...
そして暗号化後はこうなる。
$ cat secret.yml $ANSIBLE_VAULT;1.1;AES256 39623765313732333464343138313530353533336661323139373832313333303830353661356565 6537376564616138653037376331336565393035666439370a636438643734313730613130613462 61623139643335663532326330383565343535333430323263393066633434376162316635363731 3763633235303431380a646162316337383861646536303530633563323537666162393536393033 35666261636563613266336264663530386134656531373566303132306135363033373062623730 ...
ちなみに元のファイルを編集したい場合はeditすればOK。
$ ansible-vault edit secret.yml Vault password:
次はこのファイルの中身を変数として取り込むためにplaybookを編集する。
$ cat playbooks/secret_files.yml - name: import secret file include_vars: "secret.yml" no_log: true - name: locate secret files copy: content: "{{ bashrc }}" dest: ~/.bashrc mode: 0655 no_log: true
include_varsで先ほどの暗号化したファイルを指定する。
暗号化前のsecret.ymlでは"bashrc"をkeyとして設定したが、
これをplaybook内で利用するには {{ }}
で囲めば良い。
また、このままだとコンソールにパスワードが表示されてしまうので、
no_logオプションを指定して、ログに出さないようにする。
今回作ってみたコードはこちら。
yukofeb/AnsibleLocalProvisioning at 0c52471c934be93b3859cb5b5d436b64bbe84e86
ということで実行してみる。
$ brewi No config file found; using defaults Vault password: 1 plays in /Users/yukofeb/Work/github/AnsibleLocalProvisioning/playbook.yml PLAY *************************************************************************** ... TASK [import secret file] ****************************************************** ok: [localhost] => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"} TASK [locate secret files] ***************************************************** ok: [localhost] => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result"}
正常に実行でき、ログ出力も抑制されている。完璧!
参考資料
ブログシステムHugoを構築してGithub Pagesで運用する
ちょっとしたページを作成する必要があったので、Hugoで構築してみる。
HugoはGithub Pagesに構築できるらしいので、それも合わせて対応する。
作業環境
$ sw_vers ProductName: Mac OS X ProductVersion: 10.11.3 BuildVersion: 15D21
インストール
hugoをbrewで入れる。
golangなど必要なパッケージも合わせてインストールされる。
$ cd ~ $ brew install hugo
確認
$ hugo version Hugo Static Site Generator v0.15 BuildDate: 2015-11-26T01:29:07-05:00
プロジェクト作成
$ hugo new site (PJNAME) $ ls (PJNAME) archetypes config.toml content data layouts static
記事作成
記事をcreateすると、
$ hugo new test.md
contentディレクトリの下にファイルが作成される。
$ cat content/test.md +++ date = "2016-02-24T12:32:35-05:00" draft = true title = "test" +++
あとはMarkdownで書き加えていけばOK
テーマ設定
見た目をいじる。
Hugo Themes Siteを見て、良さそうなテーマを探す。
今回はagencyを使う。
ダウンロード
$ mkdir themes $ git clone --depth 1 --recursive https://github.com/digitalcraftsman/hugo-agency-theme.git themes
試しにローカルで起動させてみる。
$ hugo server --watch -t agency 0 draft content 0 future content 0 pages created 0 paginator pages created 0 tags created 0 categories created in 26 ms Watching for changes in /Users/yukofeb/Work/github/MovingSaleAtlanta/{data,content,layouts,static,themes} Serving pages from memory Web Server is available at http://localhost:1313/MovingSaleAtAtlanta/ (bind address 127.0.0.1) Press Ctrl+C to stop
GitHub Pagesに構築する
基本的にはHugo - Hosting on GitHub Pagesを順にやっていけばできる。
以下、簡単な説明。
* Github Pagesを作るにはgh-pagesブランチにpushすれば良い。
* hugoではブログ用に生成したファイルがroot配下のpublicフォルダに配置される
* subtreedコマンドを使って、サブディレクトリpublicとしてgh-pagesブランチを取り込む
* git subtree pushでgh-pagesブランチにpushすることでページを更新する
以下、上記ページを転記して少々加筆。
# Create a new orphand branch (no commit history) named gh-pages git checkout --orphan gh-pages # Unstage all files git rm --cached $(git ls-files) # Grab one file from the master branch so we can make a commit git checkout master README.md # Add and commit that file git add . git commit -m "INIT: initial commit on gh-pages branch" # Push to remote gh-pages branch git push origin gh-pages # Return to master branch git checkout master # Remove the public folder to make room for the gh-pages subtree rm -rf public # Add the gh-pages branch of the repository. It will look like a folder named public git subtree add --prefix=public git@github.com:yukofeb/MovingSaleAtAtlanta.git(自分のレポジトリに書き換える) gh-pages --squash # Pull down the file we just committed. This helps avoid merge conflicts git subtree pull --prefix=public git@github.com:yukofeb/MovingSaleAtAtlanta.git(自分のレポジトリに書き換える) gh-pages # Run hugo. Generated site will be placed in public directory (or omit -t ThemeName if you're not using a theme) hugo -t ThemeName # Add everything git add -A # Commit and push to master git commit -m "Updating site" && git push origin master # Push the public subtree to the gh-pages branch git subtree push --prefix=public git@github.com:yukofeb/MovingSaleAtAtlanta.git(自分のレポジトリに書き換える) gh-pages
これで今後は以下のフローだけでGithub Pagesが更新できるようになる。
# masterブランチを更新してpush $ git commit -m "Updating site" && git push origin master ## gh-pagesにpushする $ git subtree push --prefix=public git@github.com:yukofeb/MovingSaleAtAtlanta.git(自分のレポジトリに書き換える) gh-pages
完成ページはこちら。いい感じ!
Moving Sale at Atlanta