LoginSignup
1
1

More than 5 years have passed since last update.

ChefでVimプラグインマネージャーNeoBundleを設置する。

Last updated at Posted at 2016-02-24

関連記事

クックブックを生成

  % bin/knife cookbook create vim-plugin -o site-cookbooks

レシピを作成

  • site-cookbooks/vim-plugin/recipes/default.rb
  directory "/home/#{node['user']}/.vim" do
    owner node['user']
    group node['group']
    mode '0755'
    action :create
  end

  %w(backup bundle swap).each do |dir|
    directory "/home/#{node['user']}/.vim/#{dir}" do
      owner node['user']
      group node['group']
      mode '0755'
      action :create
    end
  end

  execute 'install neobundle' do
    user node['user']
    group node['group']
    cwd "/home/#{node['user']}"
    command 'curl -L https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh | sh'
    environment 'HOME' => "/home/#{node['user']}"
    not_if { File.exists?("/home/#{node['user']}/.vim/bundle/neobundle.vim") }
  end

  %w(.vimrc_scss_indent .vimrc).each do |file|
    cookbook_file "/home/#{node['user']}/#{file}" do
      owner node['user']
      group node['group']
      mode '0644'
    end
  end

vimの設定ファイル

実行一覧に追加

  % bin/knife node run_list add dev 'recipe[vim-plugin]' -z

処理結果

  % bin/knife solo cook dev

  ... snip ...

  Recipe: vim-plugin::default
    * directory[/home/vagrant/.vim] action create
      - create new directory /home/vagrant/.vim
      - change mode from '' to '0755'
      - change owner from '' to 'vagrant'
      - change group from '' to 'vagrant'
      - restore selinux security context
    * directory[/home/vagrant/.vim/backup] action create
      - create new directory /home/vagrant/.vim/backup
      - change mode from '' to '0755'
      - change owner from '' to 'vagrant'
      - change group from '' to 'vagrant'
      - restore selinux security context
    * directory[/home/vagrant/.vim/bundle] action create
      - create new directory /home/vagrant/.vim/bundle
      - change mode from '' to '0755'
      - change owner from '' to 'vagrant'
      - change group from '' to 'vagrant'
      - restore selinux security context
    * directory[/home/vagrant/.vim/swap] action create
      - create new directory /home/vagrant/.vim/swap
      - change mode from '' to '0755'
      - change owner from '' to 'vagrant'
      - change group from '' to 'vagrant'
      - restore selinux security context
    * execute[install neobundle] action run
      - execute curl -L https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh | sh
    * cookbook_file[/home/vagrant/.vimrc_scss_indent] action create
      - create new file /home/vagrant/.vimrc_scss_indent
      - update content in file /home/vagrant/.vimrc_scss_indent from none to 05be8b
      --- /home/vagrant/.vimrc_scss_indent  2016-02-24 09:24:30.773395982 +0000
      +++ /home/vagrant/..vimrc_scss_indent20160224-22510-1ok5kzu   2016-02-24 09:24:30.773395982 +0000
      @@ -1 +1,48 @@
      +setlocal indentexpr=GetMyIndent()
      +function! GetMyIndent()
      +    let cline = getline(v:lnum)
      +
      +    " Find a non-blank line above the current line.
      +    let lnum = prevnonblank(v:lnum - 1)
      +    " Hit the start of the file, use zero indent.
      +    if lnum == 0
      +        return 0
      +    endif
      +    let line = getline(lnum)
      +    let ind = indent(lnum)
      +
      +    " Indent blocks enclosed by {}, (), or []
      +    " Find a real opening brace
      +    let bracepos = match(line, '[(){}\[\]]', matchend(line, '^\s*[)}\]]'))
      +    while bracepos != -1
      +        let brace = strpart(line, bracepos, 1)
      +        if brace == '(' || brace == '{' || brace == '['
      +            let ind = ind + &sw
      +        else
      +            let ind = ind - &sw
      +        endif
      +        let bracepos = match(line, '[(){}\[\]]', bracepos + 1)
      +    endwhile
      +    let bracepos = matchend(cline, '^\s*[)}\]]')
      +    if bracepos != -1
      +        let ind = ind - &sw
      +    endif
      +
      +    return ind
      +endfunction
      +
      +setlocal expandtab
      +setlocal tabstop=4
      +setlocal shiftwidth=4
      +setlocal softtabstop=0
      +
      +if !exists('b:undo_indent')
      +    let b:undo_indent = ''
      +endif
      +
      +let b:undo_indent = 'setlocal '.join([
      +      \ 'tabstop<',
      +      \ 'shiftwidth<',
      +      \ 'softtabstop<',
      +      \ ])
      - change mode from '' to '0644'
      - change owner from '' to 'vagrant'
      - change group from '' to 'vagrant'
      - restore selinux security context
    * cookbook_file[/home/vagrant/.vimrc] action create
      - create new file /home/vagrant/.vimrc
      - update content in file /home/vagrant/.vimrc from none to bd2581
      (new content is binary, diff output suppressed)
      - change mode from '' to '0644'
      - change owner from '' to 'vagrant'
      - change group from '' to 'vagrant'
      - restore selinux security context

  Running handlers:
  Running handlers complete
  Chef Client finished, 9/33 resources updated in 19 seconds

困ったところ

  • 実はNeoBundleのインストールだけではなく.vimrcに書かれているすべてのプラグインをインストールするつもりだったがうまく行けなかった。
  • NeoBundleの場合、bundleをインストールするためのコマンドを提供している。
    • ~/.vim/bundle/neobundle.vim/bin/neoinstall
    • vim +NeoBundleInstall +qall
  • いずれもvimコマンドを用いてvimの実行モードで行っている。
  • レシピに下記のようにexecuteリソースを追加してためしてみたがダメだった。
  execute 'install vim plugin via neobundle' do
    user node['user']
    group node['group']
    cwd "/home/#{node['user']}"
    command "/home/#{node['user']}/.vim/bundle/neobundle.vim/bin/neoinstall"
    environment 'HOME' => "/home/#{node['user']}"
  end
  • vagrantのsandboxをonにしておいてノードで直接該当コマンドを実行してみたら次のようなエラーが発生しながら実行が止まった。
  neobundle e185: cannot find color scheme
  • 実行中に止まったのが原因ではないかと思って使っていたcolorschemeをgitで直接取得するようにリソースを追加した。
  git "/home/#{node['user']}/.vim/bundle/mopkai.vim" do
    repository node['git']['colorscheme']
    action :sync
    user node['user']
    group node['group']
  end
  • ノードではcolorschemeを探されないというメッセージは表示されなかったし、正常にプラグインが設置されたが、knife-soloを通じて実行するとできない。
  • knife-soloでノードに適用するときエラーは発生しないが、処理が早く終わるのが可笑しくてノードをみるとプラグインは設置されていなかった。
  • プラグインの設置はvimを起動すると自動で設置されるから別にchefでやらなくてもいいと思うようになって削除したが、後味が悪い。

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1