LoginSignup
2
2

More than 5 years have passed since last update.

ChefでCentOS 6.7 + Vim 7.4 + luaを設置する。

Last updated at Posted at 2016-02-23

関連記事

luaをインストール

  • luaを有効にしたVimを設置するためlua関連ライブラリをインストールする。
  • lua-develはyumで設置する。
  • luajitを設置するとluaをより高速で使える。gitリポジトリを取得してtarballで設置する。

クックブックを生成

  % bin/knife cookbook create lua -o site-cookbooks

レシピを作成

  • site-cookbooks/lua/recipes/default.rb
  package 'lua-devel' do
    action :install
  end

  src_filepath = "#{Chef::Config['file_cache_path']}/luajit"

  git "#{src_filepath}" do
    repository node['lua']['luajit_url']
    user 'root'
    group 'root'
  end

  bash 'install_luajit' do
    cwd ::File.dirname(src_filepath)
    code <<-EOH
      cd #{src_filepath}
      make && make install
    EOH
  end

実行一覧に追加

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

Vim 7.4をインストール

クックブックの生成

  • Berkshelfファイルにクックブックを追加する。
  % vi Berkshelf

  ... snip ...
  cookbook 'vim'
  • cookbooksの配下に保持する。
  bin/berks vendor cookbooks

Attributes

  • cookbooks/vim/attributes/default.rb
    • install_methodがpackageの場合、yumで設置される。
    • install_methodがsourceの場合、ソースコンパイルで設置される。
  ... snip ...
  default['vim']['install_method'] = 'package'
  • cookbooks/vim/attributes/source.rb
    • CentOS 6以上ではlua-develに依存される。
  ... snip ...

  default['vim']['source']['configuration'] = "--without-x --enable-pythoninterp --enable-rubyinterp --enable-tclinterp --enable-luainterp --enable-perlinterp --enable-cscope  --with-features=huge --prefix=#{default['vim']['source']['prefix']}"

  if platform_family? 'rhel', 'fedora'
    if node['platform_version'].to_i >= 6
      default['vim']['source']['dependencies'] = %w( ctags
                                                     gcc
                                                     lua-devel
                                                     make
                                                     ncurses-devel
                                                     perl-devel
                                                     perl-ExtUtils-CBuilder
                                                     perl-ExtUtils-Embed
                                                     perl-ExtUtils-ParseXS
                                                     python-devel
                                                     ruby-devel
                                                     tcl-devel
                                                 )

  ... snip ...
  • lua-devel、luajitの設置した後、Vimをソースコンパイルで設置するとluaを有効にしたVimが設置されるわけだ。

実行一覧に追加

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

Environmentsについて

  • 開発、ステージング、本番環境に関するAttributeはここに書いておく。

Environmentsのコマンド

  • コマンド一覧
  % bin/knife environment

  FATAL: Cannot find subcommand for: 'environment'
  Available environment subcommands: (for details, knife SUB-COMMAND --help)

  ** ENVIRONMENT COMMANDS **
  knife environment compare [ENVIRONMENT..] (options)
  knife environment create ENVIRONMENT (options)
  knife environment delete ENVIRONMENT (options)
  knife environment edit ENVIRONMENT (options)
  knife environment from file FILE [FILE..] (options)
  knife environment list (options)
  knife environment show ENVIRONMENT (options)
  • 開発環境の生成
  % bin/knife environment create development -d "The development environment." -z
  • 開発環境の編集
    • node['lua']['luajit_url']を定義
    • Vimのクックブックの中に定義されたnode['vim']['install_method']をオーバーライド
  % bin/knife environment edit development -z

  {
    "name": "development",
    "default_attributes": {
      "user": "vagrant",
      "group": "vagrant",
      "lua": {
        "luajit_url": "http://luajit.org/git/luajit-2.0.git"
      }
    },
    "override_attributes": {
      "vim": {
        "install_method": "source"
      }
    }
  }
  • 開発環境の詳細
  % bin/knife environment show development -z

  chef_type:           environment
  cookbook_versions:
  default_attributes:
    group: vagrant
    lua:
      luajit_url: http://luajit.org/git/luajit-2.0.git
    user:  vagrant
  description:
  json_class:          Chef::Environment
  name:                dev
  override_attributes:
    vim:
      install_method: source

Attributesの優先順位

ノードの環境を設定

  • chef_environmentを_defaultからdevelopmentへ変更する。
  % bin/knife node edit dev -z
  • ノードの環境を確認
  % bin/knife node show dev -z

  Node Name:   dev
  Environment: development
  FQDN:
  IP:          dev
  Run List:    recipe[yum-epel], recipe[yum-update], recipe[mariadb], recipe[ruby-env], recipe[lua], recipe[vim]
  Roles:
  Recipes:
  Platform:
  Tags:

実行結果

  • ノードに適用
  % bin/knife solo cook dev

  Running Chef on dev...
  Checking Chef version...
  Installing Berkshelf cookbooks to 'cookbooks'...
  Resolving cookbook dependencies...
  Using yum-epel (0.6.5)
  Using vim (2.0.1)
  Using yum (3.10.0)
  Vendoring vim (2.0.1) to cookbooks/vim
  Vendoring yum (3.10.0) to cookbooks/yum
  Vendoring yum-epel (0.6.5) to cookbooks/yum-epel
  Uploading the kitchen...
  Generating solo config...
  Running Chef: sudo chef-solo -c ~/chef-solo/solo.rb -j ~/chef-solo/dna.json
  Starting Chef Client, version 12.7.2
  Compiling Cookbooks...
  Converging 22 resources
  Recipe: yum-epel::default
    * yum_repository[epel] action create
      * template[/etc/yum.repos.d/epel.repo] action create (up to date)
      * execute[yum clean metadata epel] action nothing (skipped due to action :nothing)
      * execute[yum-makecache-epel] action nothing (skipped due to action :nothing)
      * ruby_block[yum-cache-reload-epel] action nothing (skipped due to action :nothing)
       (up to date)
  Recipe: yum-update::default
    * execute[yum-update] action run
      - execute yum -y update
  Recipe: mariadb::default
    * cookbook_file[/etc/yum.repos.d/MariaDB.repo] action create (up to date)
    * yum_package[MariaDB-server] action install (up to date)
    * yum_package[MariaDB-client] action install (up to date)
    * yum_package[MariaDB-devel] action install (up to date)
  Recipe: ruby-env::default
    * yum_package[gcc] action install (up to date)
    * yum_package[git] action install (up to date)
    * yum_package[openssl-devel] action install (up to date)
    * yum_package[readline-devel] action install (up to date)
    * git[/home/vagrant/.rbenv] action sync (up to date)
    * template[.bash_profile] action create (skipped due to not_if)
    * directory[/home/vagrant/.rbenv/plugins] action create (up to date)
    * git[/home/vagrant/.rbenv/plugins/ruby-build] action sync (up to date)
    * execute[rbenv install 2.3.0] action run (skipped due to not_if)
  Recipe: lua::default
    * yum_package[lua-devel] action install (up to date)
    * git[/var/chef/cache/luajit] action sync (up to date)
    * bash[install_luajit] action run
      - execute "bash"  "/tmp/chef-script20160223-16690-9llm95"
  Recipe: vim::source
    * yum_package[bzip2] action install (up to date)
    * yum_package[ctags, gcc, lua-devel, make, ncurses-devel, perl-devel, perl-ExtUtils-CBuilder, perl-ExtUtils-Embed, perl-ExtUtils-ParseXS, python-devel, ruby-devel, tcl-devel] action install
      - install version 5.8-2.el6 of package ctags
      - install version 5.10.1-141.el6_7.1 of package perl-devel
      - install version 0.27-141.el6_7.1 of package perl-ExtUtils-CBuilder
      - install version 1.28-141.el6_7.1 of package perl-ExtUtils-Embed
      - install version 2.2003.0-141.el6_7.1 of package perl-ExtUtils-ParseXS
      - install version 2.6.6-64.el6 of package python-devel
      - install version 1.8.7.374-4.el6_6 of package ruby-devel
      - install version 8.5.7-6.el6 of package tcl-devel
    * remote_file[/var/chef/cache/vim-7.4.tar.bz2] action create
      - create new file /var/chef/cache/vim-7.4.tar.bz2
      - update content in file /var/chef/cache/vim-7.4.tar.bz2 from none to d0f5a6
      (new content is binary, diff output suppressed)
      - restore selinux security context
    * bash[install_vim] action run
      - execute "bash"  "/tmp/chef-script20160223-16690-1hrglcr"

  Running handlers:
  Running handlers complete
  Chef Client finished, 5/26 resources updated in 01 minutes 33 seconds
  • ノードのVimを確認
    • ssh devで接続して、vim --versionで確認する。
    • luaに有効の場合 +luaが表示される。
  % ssh dev
  $ vim --version

  ... snip ...

  +dialog_con      +lua             +rightleft       +windows

  ... snip ...

参考

2
2
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
2
2