ansibleでmacbookを管理
はじめに
先日、macbookが起動しなくなり仕方なくクリーンインストールしたので、今後のことも考えてmacbookの環境を管理する
環境
brew と brew caskは導入済み $ brew install ansible 上記、コマンドを実行済み $ ansible --version ansible 2.5.0
今回用意した2つのファイル
hosts
localhost
localhost.yml
--- - hosts: localhost connection: local gather_facts: no become: no vars: homebrew_packages: - name: python - name: fish - name: git - name: node - name: pyenv - name: tree - name: vim homebrew_cask_packages: - name: google-chrome - name: google-drive - name: virtualbox - name: vagrant - name: iTerm2 - name: atom - name: docker - name: evernote - name: dropbox - name: slack tasks: - name: update homebrew homebrew: update_homebrew=yes # brew - name: install homebrew_packages homebrew: name={{ item.name }} with_items: '{{ homebrew_packages }}' # homebrew_cask - name: install homebrew_cask_packages homebrew_cask: name={{ item.name }} with_items: '{{ homebrew_cask_packages }}'
$ ansible-playbook -i hosts localhostsyml
これで、homebrew_packagesとhomebrew_cask_packagesに記述したソフトウェアをインストールできる
Dockerのインストールからコンテナ作成まで
開発環境
ubuntu/trusty64
Dockerのインストール
$ sudo apt-get update $ sudo apt-get -y install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo apt-key fingerprint 0EBFCD88 $ sudo add-apt-repository -y \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" $ sudo apt-get update $ sudo apt-get install -y docker-ce
Dockerコマンド
ローカルに保存されたdockerイメージの一覧を取得
$docker images
docker hubにあるイメージを検索
$docker search <イメージ>
docker hubにあるイメージをローカルに取得する
$docker pull <イメージ>
コンテナでプロセスを起動する
$docker run -it <イメージ> /bin/bash
起動したコンテナはexitすれば自動的に終了
プロセスを確認する(停止されたものも含む)
$ docker ps -a
停止されたコンテナの削除
$ docker rm <コンテナid>
idは一意なので頭の4桁程度入力すればOK
何度もコンテナの起動と停止を行なっていると大量にプロセスが生まれるのでそれを避けたい
コンテナを全て削除
$ docker rm $(docker ps -aq)
exitと同時にコンテナの削除
$docker run --rm -it <イメージ> /bin/bash
ポートをホスト側に公開して起動
$ docker run -it -p 80:80 <イメージ> /bin/bash
外部ファイルを取り込む
$ docker run -it -v <ホスト側のパス>:<コンテナ側のパス> <イメージ> /bin/bash
Dockerfile作成してからの流れ
Dockerfileからイメージを作成
$ docker build -t <作成するイメージ名> .
作成したイメージからコンテナを起動
$ docker run --name <起動するコンテナ名> -d -p <イメージ名>
コンテナの停止
$ docker stop <コンテナ名>
hexoとやらを試してみた
hexo
githubのアカウントあれば誰でもブログを公開できる
まずはリポジトリ作成
[username].github.io というリポジトリを作成
hexoの準備
公式通りに hexoをグローバルにインストール
$ npm install hexo-cli -g
以下のコマンドでディレクトリを作成
$ hexo init blog
作成されたディレクトリに移動して、モジュールをインストール
$ cd blog $ npm install
インストールできたら、以下のコマンドで起動
$ hexo server
http://localhost:4000/にアクセスすると雛形ができている
githubで公開
作成されたディレクトリ配下にあるconfig.ymlを弄る config.ymlではサイトのタイトル等を変更可能
deploy: type: git repo: https://github.com/[username]/[username].github.io.git branch: master
編集したら、以下のコマンドでデプロイ
hexo deploy -g
エラーがでた
どうやら、hexo-deployer-gitというモジュールをインストールしないといけないよう
ってことでインストール
$ npm install hexo-deployer-git --save
改めてデプロイ
$ hexo deploy -g
https:[username].github.io/にアクセスすると先程http://localhost:4000/でみたページにアクセス可能
※反映にそれなりに時間が掛かる
テーマの導入
こちらのサイトから気に入ったプラグインclone
例えば、これなら github.com READMEにあるようにコマンドを実行
$ git clone https://github.com/mkkhedawat/clexy themes/clexy $ git clone https://github.com/mkkhedawat/clexy themes/clexy $ yarn remove hexo-renderer-ejs $ yarn add hexo-renderer-jade $ yarn add hexo-prism-plugin
_config.ymlを編集
prism_plugin: mode: 'preprocess' # realtime/preprocess theme: 'default' line_number: false # default false theme: clexy
デプロイ
hexo deploy -g
記事の投稿
以下のコマンドを実行
$ hexo new post 新規ページ
source/post/新規ページ.mdが作成されているので弄ってpushすれば記事が投稿できる
ところで、hexoってなんて読むんだろう・・・?
JavaScriptの非同期処理(Promise)
Promise.resolve().then(function() { return new Promise(function(fulfilled, rejected) { //処理1 fulfilled(); }); }).then(function() { return new Promise(function(fulfilled, rejected) { //処理2 fulfilled(); }); }).then(function() { return new Promise(function(fulfilled, rejected) { //処理3 }); })
vagrant の共有ディレクトリでnpm installがエラーを吐く時
sudo npm install --no-bin-links
--no-bin-linksをつければうまくいく
vagrant + Ubuntu 16.04 LTS でDjango開発環境を構築
はじめに
vagrantでUbuntu 16.04 LTSの準備
ubuntu 16.04 LTSのboxを持っていることが前提
Vagrantfileの作成
$ vagrant init ubuntu/xenial64
作成されたVagrantfileのポートを設定
$ vim Vagrantfile
下記の部分を変更
config.vm.network "forwarded_port", guest: 8000, host: 8000
起動
$ vagrant init ubuntu/xenial64
接続
$ vagrant ssh
Djangoのインストール
pipのインストール
$ wget https://bootstrap.pypa.io/get-pip.py $ sudo python3 get-pip.py $ sudo pip install Django
Ubuntu 16.04 LTSにはデフォルトでpython3.5.2が入っている
バージョンの確認
$python3 -m django --version 1.11.5
Djangoを使ってみる
プロジェクトの作成
$ django-admin startproject mysite
作られたプロジェクトを見てみる
$ tree . ├── get-pip.py └── mysite ├── db.sqlite3 ├── manage.py └── mysite ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-35.pyc │ ├── settings.cpython-35.pyc │ ├── urls.cpython-35.pyc │ └── wsgi.cpython-35.pyc ├── settings.py ├── urls.py └── wsgi.py
作成したプロジェクトのディレクトリに移動
$ cd mysite
Djangoを動かしてみる
python3 manage.py runserver 0.0.0.0:8000
ローカルマシンからアクセス http://127.0.0.1:8000/
It worked!
dein.vimを使ってみる
curl を使ってシェルをダウンロード
curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh -o /tmp/installer.sh
シェルの実行
sh /tmp/installer.sh ~/.vim/dein
"dein Scripts----------------------------- if &compatible set nocompatible " Be iMproved endif " Required: set runtimepath+=/home/ubuntu/.vim/dein/repos/github.com/Shougo/dein.vim " Required: if dein#load_state('/home/ubuntu/.vim/dein') call dein#begin('/home/ubuntu/.vim/dein') " Let dein manage dein " Required: call dein#add('/home/ubuntu/.vim/dein/repos/github.com/Shougo/dein.vim') " Add or remove your plugins here: call dein#add('Shougo/neosnippet.vim') call dein#add('Shougo/neosnippet-snippets') " You can specify revision/branch/tag. call dein#add('Shougo/vimshell', { 'rev': '3787e5' }) " Required: call dein#end() call dein#save_state() endif " Required: filetype plugin indent on syntax enable " If you want to install not installed plugins onstartup. "if dein#check_install() " call dein#install() "endif "End dein Scripts-------------------------
コンソールに表示された↑を home直下の .vimrcに追記